I have made a form in which a person puts up his details.
After completing the form and submitting it, I want a popup which should ask "Do you want to add more?","Yes or No ?".
If Yes is chosen, the some values filled in the form should be retained and the rest should appear blank.
On NO the page should get freshened with everything blank.
I am able to retain the values of the drop down items and text fields,but I am not able to retain the values of the check box items.
My check box code :
<label>Hotel Facilities</label>
</td><td class="row1"> :</td> <td class="row1" width="70%">
<div style=" font-weight:normal; color: #4B4B4B;font-size: 12px; width:260px; background:#D2D2D2; max-height:300px; overflow:scroll;overflow-x:hidden;">
<?php $dcs=mysql_query("select * from `tblfacility` where `Type`='Rm'");
while($dc=mysql_fetch_array($dcs)){?>
<input type="checkbox" name="check_list[]" value="<?php echo $dc['FId']; ?>">
<?php echo $dc['Facility'];?> <br />
<?php }?>
</div>
I tried to retain by using:
<input name="check_list[]" type="checkbox" value="<?php echo $dc['FId']; ?>" <?php if(isset($_POST['check_list[]'])) echo "checked='checked'"; else echo $dc['Facility']; ?>
but it did not worked
Please help me how to retain its values after submitting that page.
And the pop up I am at present using is just an alert message and hence it just have OK button:
<?php
if(isset($_POST['submit'])){
echo "<script>alert ('Do You want to Add More ?');</script>";
$HId=$_POST['HId'];
?>
hence it is just showing OK button after submitting .
Please guide how to put Yes or No button after submitting hence is Yes some values will be retained and if NO the whole from will be refreshed.
Instead of checked='checked' just use "selected" or "selected=true". I hope it works!
Related
I have 2 check boxes and I want to keep the check box value after page refresh too. I mean if I enable a check box and after I submit the form if I navigate back or refresh the page it should be enable only.
I tried this but not working.
<input type="checkbox" id="enable1" name="check[0]" value= "1"
<?php if (in_array("0", $_POST['check'])) echo "checked='checked'"; ?> />
<input type="checkbox" id="enable2" name="check[1]" value= "1"
<?php if (in_array("1", $_POST['check'])) echo "checked='checked'"; ?> />
Please help me with this how to keep the state of check boxes after page reload
thanks..
My issue is once user click submit the form should check for all questions that the radio button is checked.
It should show the err message on the questions where the user didn't answer.
But right now the form refreshed everytime after the err message is shown and the
previous checked radio button is lost.I also have javascript timer going on,but
since the page get refreshed ,the timer starts all over again.
Im newbie to php,kindly guide me through this issue.Any help is appreciated.
<?php session_start()?>
<?php
$errorexist=false;
if (isset($_POST["submit"])){
for ($y=0;$y<5;$y++)
{
if(empty($_POST["question".$y])){
$errorexist=true;
${"err".$y}="* Please answer question ".($y+1)."<br>";
}
}
if (errorexist==false){
header ("Location: result.php");
exit;}
} ?>
html part of the code
<li>
<span class="error"><?php echo $err0?></span>
<h3>What is the smallest prime number?</h3>
<input type="radio" name="question0" value="A"<?php echo ($question0=='A')? 'checked':''; ?> />2<br>
<input type="radio" name="question0" value="B"<?php echo ($question0=='B')? 'checked':''; ?> />1<br>
<input type="radio" name="question0" value="C"<?php echo ($question0=='C')? 'checked':''; ?> />3<br>
<input type="radio" name="question0" value="D"<?php echo ($question0=='D')? 'checked':''; ?> />4<br>
</li>
Put a condition, where if any radio button misses it displays the
error message and no need to refresh the page. Inside the PHP code,
Request submit button
Request all the radio button. i.e $question1 = $_REQUEST['question1'];
check if all the values are set and not empty if(isset($question1) && !empty($question1) && $question1 !== '')
do this for all, close this condition with the error message.
This might help.
What i want is pretty simple, i have a button that submits a value to my database once clicked, what i need is to diable the button parmanently after value has been submited, i have searched and the codes i have seen all enable the button when the page refreshes.. please can someone help me out?
My form and button code as follows:
<form action="<?php echo $editFormAction; ?>" method="POST" name="Status2" id="Status2" onSubmit="return confirm('Are you sure you want to submit?');">
<input name="Confirm2" type="checkbox" id="Confirm2" value="Confirmed" checked="CHECKED" style="display:none;">
<label for="Confirm2"></label>
<input name="UpdateButton3" type="submit" class="art-button" id="UpdateButton3" value="Confirm"/>
<input name="UserIDHiddenField4" type="hidden" id="UserIDHiddenField4" value="<?php echo $row_User['UserID']; ?>">
<input name="Purge2" type="checkbox" id="Purge2" value="You Will Be Rematched Soon!" checked="CHECKED" style="display:none;">
<label for="Purge2"></label>
<input type="hidden" name="MM_update" value="Status2">
</form>
First of all if you submit it, this has nothing to do with javascript. Save this in your database as #georoot says. Then when you submit, save a value in the database. If that value is set, you can disable the button by just HTML:
<input type="submit" <?php if($valueFromDatabase==1){ ?> disabled <?php } ?> >
Best solution could be to set a cookie on client system and/or get user IP and save it into your database, but you should keep in mind, non of them are permanent ! The IP can be changed and the cookie can be removed ! But you can use both cookie and IP check.
Then for each page load, just check if cookie exist (compare the value with ur database value) and/or client IP is already exist in database.
Or if you know who is on the page (if it's a logged user) just add a field in your database and set value = 1 or = 0 and check the field each time it's loaded for same field and for same user.
I wouldn't recommend to use IP check without cookies ! Because it can change frequency !
I have the following Problem
I get a variable from PHP via:
echo $var
Actually this takes place in:
<a href:"..\test.php?go=<?php echo $var ?>">
And to a page where you can get more info about $var...
Today i learned about the display attribute from a div, so i can display the info via Ajax direct in my actual page. So, I tried:
<Label id="123" onclick="doJS(<?php echo $var ?>)> Click ME </Label>
But this doesn't work, I cant click the label, just nothing happens.
How can this be solved?
You have a typo in your code.
Replace
<Label id="123" onclick="doJS(<?php echo $var ?>)> Click ME </Label>
By
<Label id="123" onclick="doJS(<?php echo $var ?>)"> Click ME </Label>
So you should try:
<label id='123' onclick="doJS(<?=$_GET['go']?>)"> Click ME </label>
I'm hoping a javascript / jquery guru can help me out.
I'm trying to figure out a way to launch a popup box (fancybox) from the click of a checkbox label. I don't want to effect the checkbox function which filters data when clicked.
I would welcome any thoughts on how I can make this happen. I've tried an onclick function on the label but that doesn't work.
I want to show a fancybox when you click on a persons name in the checkbox label. Here's the site:- (example: jonathanlyon)
http://monkeygetnews.jonathanlyon.com/bs.php
The checkboxes are built dynamically and I need to create a click event on the label that opens a fancybox. Here's the code to build the checkboxes:-
<input type="checkbox" id = "dn" value="dept_<?php echo $currdept;?>" onchange="doSearch();return false;" />
<label><?php echo $currdept;?></label>
<ul class="dept_<?php echo $currdept;?>">
<li>
<input type="checkbox" name = "un" value="<?php echo $usernames;?>" <?php echo $include;?> onchange="doSearch();return false;" />
<label><?php echo $usernames;?></label>
</li>
<?php
$dept = $currdept;
} else {
?>
<li>
<input type="checkbox" name = "un" value="<?php echo $usernames;?>" <?php echo $include;?> onchange="doSearch();return false;" />
<label><?php echo $usernames;?></label>
</li>
<?php
$dept = $currdept;
}
?>
Thanks
Jonathan
Very simply put you can use jquery like this
$('label').click(function() {
alert($(this).html());
}
again, this is a very simple example and would need improvement
You need to wrap checkbox tag with label tag to make label clickable like
<label><input type="checkbox" name="checkbox" value="value"/>dasfaha</label>
Edit:
Sorry guys. I didn't look carefully. Here is how to detect label or checkbox.
How it works is that when you click unbounded label, checkbox won't be changed. However, when you click checkbox, ':checked' will be changed. Thus, you can put a variable to store previous value of checked, then compare with current checked.
http://jsfiddle.net/Xtyah/