Page 1 of 1

Keep Option Selected after form submission

Posted: 21 Oct 2016, 06:19
by JanMolendijk
I have this code to update one from your scripts
But if i select the option Other it does not stay in de admin on this same line
I hope you could help me out

Code: Select all

<?
if($object->user_facebook=="Male"){
$ga = "selected";
}
elseif($object->user_facebook=="Female"){
$gb = "selected";
}
else{
$gc = "selected";
}
?>
  <select size="1" name="user_facebook">
  <option value="Male"<? echo $ga ?>>Male</option>
  <option value="Female"<? echo $gb ?>>Female</option>
  <option value="Other"<? echo $gc ?>>Other</option>
  </select><br>
I Searching few hours for an answer but still nothing
Hope you realy could help me out.
Keep values selected after form submission ???

Keep Option Selected after form submission

Posted: 21 Oct 2016, 09:27
by Admin
Hello
I did not understand what you mean with: "it does not stay in de admin on this same line".
To keep option selected after form submission in your code, try this;

Code: Select all

<?php
$ga = $gb = $gc ='';
if(isset($_POST['user_facebook'])){
  if($_POST['user_facebook']=='Male') $ga =' selected';
  else if($_POST['user_facebook']=='Female') $gb =' selected';
  else if($_POST['user_facebook']=='Other') $gc =' selected';
}
?>
<select size="1" name="user_facebook">
<option value="Male"<? echo $ga; ?>>Male</option>
<option value="Female"<? echo $gb; ?>>Female</option>
<option value="Other"<? echo $gc; ?>>Other</option>
</select><br>

Keep Option Selected after form submission

Posted: 21 Oct 2016, 11:22
by JanMolendijk
Thanks for the Quick answer i found also a way to do it like this

Code: Select all

 Gender <select name="user_facebook" class="footerlink" value ="<? echo $user_facebook ?>" >



<option value="<?php echo $rws['user_facebook'];?>" <?php if($_POST['user_facebook'] == '') echo 'selected="selected"' ?>><?php echo $rws['user_facebook'];?></option>
<option value=""></option>
<option value="Male" <?php if($_POST['user_facebook'] == 'Male') echo 'selected="selected"' ?>>Male</option>

<option value="Female" <?php if($_POST['user_facebook'] == 'Female') echo 'selected="selected"' ?>>Female</option>

<option value="Neutral" <?php if($_POST['user_facebook'] == 'Neutral') echo 'selected="selected"' ?>>Neutral</option>

</select>

Keep Option Selected after form submission

Posted: 21 Oct 2016, 11:59
by JanMolendijk
I hope you able to understand this problem
my English is only a little :D

I have a other problem now... I wanna make a on off switch,
but when i use this code my e-mail adress is comming into
option selected... But i would like to have only the words on or off
into the option selected with the switch on off from my e-mail-adress

Code: Select all

E-mail (on-off)<?php
$ga = $gb = $gc ='';
if(isset($_POST['user_youtube'])){
  if($_POST['user_youtube']=='On') $ga =' selected';
  else if($_POST['user_youtube']=='Off') $gb =' selected';

}
?>
<select size="1" name="user_youtube">
<option value="<?php echo $rws["user_youtube"];?>"><?php echo $rws["user_youtube"];?></option>
<option value=""></option>
<option value="<?php echo $rws["user_email"];?>"<? echo $ga; ?>>On</option>
<option value="Off"<? echo $gb; ?>>Off</option>

</select><br>

Keep Option Selected after form submission

Posted: 21 Oct 2016, 14:10
by Admin
Just delete the <option> that shows the e-mail address, and keep only the On /Off <option>s.
Something like this;

Code: Select all

<?php
$ga = $gb ='';
if(isset($_POST['user_youtube']) && strlen($_POST['user_youtube'])>0){
  if($_POST['user_youtube']=='Off') $gb =' selected';
  else $ga =' selected';

}
?>
<select size="1" name="user_youtube">
<option value=""></option>
<option value="<?php echo $rws["user_email"];?>"<? echo $ga; ?>>On</option>
<option value="Off"<? echo $gb; ?>>Off</option>
</select>

Keep Option Selected after form submission

Posted: 21 Oct 2016, 19:54
by JanMolendijk
Thank you Admin & tomorow i go
on with it first a good sleep :roll:

Keep Option Selected after form submission

Posted: 22 Oct 2016, 06:23
by JanMolendijk
The problem is the option on off does not stay selected in my script
do you known if their is an other posibility ?

Keep Option Selected after form submission

Posted: 22 Oct 2016, 14:12
by Admin
The code from the previous answer should work. I not know way in your script it not works.
The code adds the "selected" attribute, after form submission, at the selected option.
Check the page source to see how it is the resulted html code.

Keep Option Selected after form submission

Posted: 22 Oct 2016, 15:36
by JanMolendijk
Thank you Admin for the support