Confirm box with button "yes" "no" without jquery and VBscript [duplicate] - php

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Javascript Confirm popup Yes, No button instead of OK and Cancel
Please someone help me to make a confirm box with button "Yes" and "No" without using jquery or VB.Script. I have searched a lot but I got all of the answers with jquery but that is not my requirement.
I have to call another function from confirmbox function. The code I am using below
HTML
Delete
And Javascript
<script type="text/javascript">
function show_confirm(cat_id)
{
var conf = confirm("Are you sure you want to delete the file");
if (conf ==true)
{
deleteCatagory(cat_id);
}
}
function deleteCatagory(cat_id)
{
var obj = document.getElementById("file_"+cat_id);
callAjax(cat_id,obj);
}
</script>

Very simple. You'll have to custom code an HTML box that has a Yes and No button. The Yes button executes the code and hides the box, the No button just hides the box. Something as simple as this would do:
HTML
<div id="confirmation">
Are you sure you want to delete the category?<br>
<input type="button" onclick="deleteCategory(document.getElementById('catID').value);this.parentNode.style.display='none';" value="Yes">
<input type="button" onclick="this.parentNode.style.display='none';" value="No">
<input type="hidden" id="catID" value="0">
</div>
CSS
<style type="text/css">
<!--
#confirmation {
display: none;
position: absolute;
top: 50%;
left: 50%;
background-color: white;
border: 2px solid white;
padding: 3px;
text-align: center;
width: 200px;
height: 50px;
}
</style>
Updated show_confirm():
function show_confirm(catID) {
document.getElementById('catID').value=catID;
document.getElementById('confirmation').style.display='block';
}

You need to create it yourself, this: http://dev.sencha.com/deploy/ext-4.0.0/examples/message-box/msg-box.html seems to have a way to do it but this is from 5 minutes of googling. Others suggest using a div to do it, which is my personal preference.

If you're fine with the "Ok" or "Cancel" options the confirm box gives you, you only need to fix the typo in your call. I'd do it like this
Delete​
If you however want to change the default text then you're out of luck with the default confirm popup. You'll have to come up with a html based "popup".

Related

How can i check class in css with checbox in Laravel?

So i want to change css class in HTML with checkbox. I know how boolean works, but how can i change text. For example, if checkbox is checked i want to inject "pull-right" class, and if it's not, then "pull-left" is defaulf.
I tried few things, but it wont work. Anyone knows how to create this?
You can try doing it like this:
Sample HTML:
<div id="container" class="pull-left">Some Content </div>
<input type="checkbox" id="mybox"/>
Sample Javascript
$("#mybox").on("change", function(){
$('#container').toggleClass("pull-left").toggleClass("pull-right");
})
Working sample on jsfiddle
I don't see any jquery tag to your question. so let me give you pure javascript solution:
fiddle: http://jsfiddle.net/Nz8Tq/
html:
<input type="checkbox" name="change" id="change"/>change class
<div class="pull-left" id="container"></div>
javascript:
document.getElementById("change").onchange = function(){
if(this.checked){
document.getElementById("container").setAttribute("class","pull-right");
} else {
document.getElementById("container").setAttribute("class","pull-left");
}
}
CSS only Demo
The :checked pseudo-class in CSS selects elements when they are in the selected state. It is only associated with input <input> elements of type radio and checkbox . The :checked pseudo-class selector matches radio and checkbox input types when checked or toggled to an on state. If they are not selected or checked, there is no match.
Browser Support
Chrome Safari Firefox Opera IE Android iOS
Any 3.1+ Any 9+ 9+ any any
source
CSS
input[type=checkbox] ~ div { /* I used general sibling selector u can use other css selectors according to ur requirement like adjacent sibling, child selector etc */
color: #ccc;
font-style: italic;
float: left
}
input[type=checkbox]:checked ~ div {
color: #f00;
font-style: normal;
float: right
}
input[type=checkbox] {
position: fixed;
}
HTML
<input type="checkbox" id="chkbx" name="chkbx">
<br>
<div for="chkbx">The power of css</div>
You can do it easily by doing this:
Jquery
$(function(){
$("input[name=toggle-checkbox]").on("change", function(){
$(".test").toggleClass("pull-left").toggleClass("pull-right");
});
});
Then in your html add this:
<input name="toggle-checkbox" type="checkbox" />
<div class="test pull-left"></div>
And a bit of css to see the effect:
.test{
display:block;
width:100px;
height:100px;
}
.pull-left{
background-color:red;
}
.pull-right{
background-color:yellow;
}
I hope this helps!!! :)

Echo Javascript function in PHP to display modal not displaying properly

i have a code here which is intended to show a Javascript modal when a textbox is not filled (when send button is clicked it will check for unfilled textboxes and checkbox AND SHOW THE MODAL, if everything is fine, it will send an email...Im working on the textbox first). But I have some problem displaying the modal properly. It seems like when i use display: block it will be shown along with other objects in the form. but when i set it to display: none, nothing is being displayed even after the send button is clicked.
Here's the CSS for modal:
#overlay {
display: block;
position: absolute;
left: 0px;
top: 0px;
width:100%;
height:100%;
text-align:center;
z-index: 800;
}
#overlay div {
width:800px;
margin: 100px auto;
background-color: none;
border:none;
padding:15px;
text-align:center;
}
body {
height:100%;
width:100%;
margin:0;
padding:0;
overflow:auto;
}
HTML:
<div id="overlay">
<div>
<img src="images/NoUsername.png" alt="module" style="width:469px; height:345px;">
<p>[<a href='#' onclick='overlay()'>close</a>]</p>
</div>
I got these codes from http://raventools.com/blog/create-a-modal-dialog-using-css-and-javascript/
Here is the PHP code for checking the textbox:
if ($username == "") {
echo
"<script type=\"text/javascript\">
function overlay() {
el = document.getElementById(\"overlay\");
el.style.visibility = (el.style.visibility == \"visible\") ? \"hidden\" : \"visible\";
}</script>";
}
I tried using double and single quotations here but nothing happens. I think the problem is in my CSS. Please feel free to edit my code. Thanks in advance for your help guys!
As I commented, you should study a little more CSS and HTML before going straight through programming like PHP and JavaScript. Your question will probably be flagged as low quality before you can really learn something meaningful from it.
I think the visibility attribute isn't suitable for your needs, as it allocates space in the DOM for the element even though it's hidden. I also think you should choose between showing the modal by PHP (server-side) or by JavaScript (client-side) as what you're doing now is becoming very confuse, even more for a novice.
I would modify your CSS to:
#overlay {
display: none; /* hidden if not overwritten by style="" attribute or javascript */
position: fixed; /* fixed makes more sense here as it doesn't depend on the element's parents, search for it */
...
IF you choose to show or hide the modal by php, it would be something like
<div id="overlay" <?php if ($username == "") echo 'style="display: block;"' ?>>
<div>
<img src="images/NoUsername.png" alt="module" style="width:469px; height:345px;">
...
OR, in my opinion the best approach, making it entirely in JavaScript (client-side), without relying on php:
<script type="text/javascript">
function show_modal() {
el = document.getElementById("overlay");
el.style.display="block";
}
function hide_modal() { // You'll want to use this for the close button
el = document.getElementById("overlay");
el.style.display="none";
}
function verify_elements() {
el = document.getElementById("username");
if (el.value == '') {
show_modal(); // if the username is '', show'em the modal
return false; // returning false makes sure the form isn't submited
}
}
</script>
<form action="" method="post" onsubmit="verify_elements()">
<input name="username" id="username" value="" />
...
I hope it helps to put you in right path. But you should really go step-by-step into this if you really want to learn instead of copy-and-paste forever :D
Best Regards!
I think that you missed to call the function added to the page:
if ($username == "") {
echo
"<script type=\"text/javascript\">
function overlay() {
el = document.getElementById(\"overlay\");
el.style.visibility = (el.style.visibility == \"visible\") ? \"hidden\" : \"visible\";
}
overlay();
</script>";
}
Also, I believe that the overlay should be hidden by default:
#overlay {
display: block;
position: absolute;
left: 0px;
top: 0px;
width:100%;
height:100%;
text-align:center;
z-index: 800;
visiblity: hidden;
}

Is there another way in PHP to use forms without using check marks or radio buttons to send data?

I was wondering if there is another way in PHP or HTML to use forms without having to have check marks or radio buttons .. For example , if I just click on a link or picture , it can send data to the other PHP file according specified in form action ... I'd like to know if I can just make picture icons send data to the other php page in form action without having to use radio buttons .. but I guess if someone only has to choose one icon from many available .. radio buttons could be the only option available or am I wrong ?
I like to use the button element. Throw in a type="submit", and you have yourself a party.
Demo: http://jsfiddle.net/RnYeg/
HTML
<form method="post" action="">
<button type="submit" name="animal" value="pig">Go</button>
</form>​
CSS
button {
background: transparent url(http://lorempixel.com/output/animals-q-c-200-200-6.jpg) 0 0 no-repeat;
border: none;
cursor: pointer;
height: 200px; width: 200px;
}​
Alternatively, you could just use an img tag:
Demo: http://jsfiddle.net/umuaU/2/
HTML
<form method="post" action="">
<button type="submit" name="animal" value="pig"><img src="http://lorempixel.com/output/animals-q-c-200-200-6.jpg" alt="Pig" /></button>
</form>​
CSS
button {
background: none;
border: none;
cursor: pointer;
margin: 0;
padding: 0;
}​

form wont send data in ie8

I have a form on my page, with one text input and one submit input, that sends info to a php script. Users can submit the form either by pressing 'enter' on their keyboard, or clicking the submit button.
In IE9 and ever other browser, the user can hit 'enter' or click the submit button and everything works fine, but in IE 8 if the user clicks the submit button, it works fine, but if they press 'enter' the form does not send the info.
The form opens up a new tab, so i know the form is submitting when the user hits 'enter', its just that the information does not send to the new page on IE8.
Anyone have some suggestions?
Thanks!
Code:
<form action="/search.php" method="post" onsubmit="location.reload(true)" target="_blank" name="myform">
<table style="width: 100%; min-width: 728px; margin: 150px 0px 170px 0px; text-align: center;">
<tr>
<td valign="middle"><img alt="Logo" src="vivvulogo.png" /><br />
<input maxlength="256" name="query" id="query" style="width: 400px; height: 25px; font-size: medium;" type="text" />
<input name="submit" style="height: 30px; width: 120px; height: 30px; font-size: medium; background-color: #CCCCCC; border-style: solid; border-color: #999999; border-width: 1px; vertical-align: top;" type="submit" value="Search" /><br />
</td>
</tr>
</table>
</form>
If you are using a button tag, hitting enter won't submit the form...
Hiding submit buttons by using display:none, positioning them off the page, hiding them inside an overflow:hidden, or any other method will break the enter-to-submit functionality as well.
If a form is hidden when the page loads and is displayed using JavaScript, the enter-to-submit will also be broken.
It appears that Internet Explorer scans the page at load time and figures out which submit buttons are visible, then attaches the enter-to-submit functionality to those forms.
Without seeing any of your code it is difficult to tell what exactly is the best solution for you, but to fix these scenarios, you can usually use the following JavaScript:
function addInputSubmitEvent(form, input) {
input.onkeydown = function(e) {
e = e || window.event;
if (e.keyCode == 13) {
form.submit();
return false;
}
};
}
window.onload = function() {
var forms = document.getElementsByTagName('form');
for (var i=0;i < forms.length;i++) {
var inputs = forms[i].getElementsByTagName('input');
for (var j=0;j < inputs.length;j++)
addInputSubmitEvent(forms[i], inputs[j]);
}
};
If you're looking for a jQuery solution...
$(function(){
$('input').keydown(function(e){
if (e.keyCode == 13) {
$(this).parents('form').submit();
return false;
}
});
});
Try using
target="_self"
instead of
target="_blank"
Hope this should work.

How do I replace the Submit Button with an Image? [jQuery jQtransform plugin]

I'm using a jQuery plugin called jQtransform (http://www.dfc-e.com/metiers/multimedia/opensource/jqtransform/) which skins HTML form elements like the input box and submit buttons. All is well until I need to use an image as the submit button. I tried the following CSS code but the original button still appears, and not the image.
CSS:
/* this is the submit button */
#search {
width: 32px;
height: 32px;
padding: 0px;
margin: 0px;
border: 0px;
background: transparent url(../images/template/icons/search.png) no-repeat center top;
overflow: hidden;
cursor: pointer; /* hand-shaped cursor */
cursor: hand; /* for IE 5.x */
}
HTML:
<input type="submit" name="search" value="Search" id="search" />
** HTML code looks like it has been processed by the jQuery plugin when viewed in Chrome's 'Inspect Element' feature. The above is the original HTML code as seen when you select 'View Page Source' in Chrome.
What should I do to replace the submit button with my own image? I'm not too good with jQuery...
UPDATE
GREAT! All the answers are working. I must have been thinking too much :)
This should work
<form>
<input type="image" src="[some image]" onsubmit="submitForm();" id="search">
</form>
How about using good old HTML <input type="image" ... />?
<img type="image" src="img src..." id="search" />

Categories