Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #13905 > unrolled thread

html php form second drop down select dependant list to keep selected value

Started byba pa <pppbbb10@gmail.com>
First post2014-06-19 09:20 -0700
Last post2014-06-19 14:40 -0700
Articles 5 — 2 participants

Back to article view | Back to comp.lang.php


Contents

  html php form second drop down select dependant list to keep selected value ba pa <pppbbb10@gmail.com> - 2014-06-19 09:20 -0700
    Re: html php form second drop down select dependant list to keep selected value Jerry Stuckle <jstucklex@attglobal.net> - 2014-06-19 13:08 -0400
      Re: html php form second drop down select dependant list to keep selected value ba pa <pppbbb10@gmail.com> - 2014-06-19 10:22 -0700
        Re: html php form second drop down select dependant list to keep selected value Jerry Stuckle <jstucklex@attglobal.net> - 2014-06-19 16:45 -0400
          Re: html php form second drop down select dependant list to keep selected value ba pa <pppbbb10@gmail.com> - 2014-06-19 14:40 -0700

#13905 — html php form second drop down select dependant list to keep selected value

Fromba pa <pppbbb10@gmail.com>
Date2014-06-19 09:20 -0700
Subjecthtml php form second drop down select dependant list to keep selected value
Message-ID<37222863-7713-4549-882a-ede165dc1c80@googlegroups.com>
Hi,

Is there a way to have the second drop down select list to keep the selected value after user hits submit?

<select class="select_Y" name="FLexA" id="LexikA">
	<option value="0" >Please choose a context...</option>
	<option value="1" <?php if (@$_POST['FLexA']==1) {echo "selected='selected'"; } ?> >Human nature , Health, Ethic, Religion...</option>
</select>

<select class="select_Y" name="FLexB" id="LexikB" jqsd:depends_on="LexikA" jqsd:hide_mode="disable">
	<option value="0" rel="0" >Please choose...</option>
	<option value="2" rel="1" <?php if (@$_POST['FLexB']==2) {echo "selected='selected'"; } ?> >Business, Law, Financezzz...</option>	
	<option value="3" rel="1" <?php if (@$_POST['FLexB']==3) {echo "selected='selected'"; } ?> >Sport, competition...</option>
</select>

Thansk,
Pascal

[toc] | [next] | [standalone]


#13906

FromJerry Stuckle <jstucklex@attglobal.net>
Date2014-06-19 13:08 -0400
Message-ID<lnv5dg$mn7$1@dont-email.me>
In reply to#13905
On 6/19/2014 12:20 PM, ba pa wrote:
> Hi,
> 
> Is there a way to have the second drop down select list to keep the selected value after user hits submit?
> 
> <select class="select_Y" name="FLexA" id="LexikA">
> 	<option value="0" >Please choose a context...</option>
> 	<option value="1" <?php if (@$_POST['FLexA']==1) {echo "selected='selected'"; } ?> >Human nature , Health, Ethic, Religion...</option>
> </select>
> 
> <select class="select_Y" name="FLexB" id="LexikB" jqsd:depends_on="LexikA" jqsd:hide_mode="disable">
> 	<option value="0" rel="0" >Please choose...</option>
> 	<option value="2" rel="1" <?php if (@$_POST['FLexB']==2) {echo "selected='selected'"; } ?> >Business, Law, Financezzz...</option>	
> 	<option value="3" rel="1" <?php if (@$_POST['FLexB']==3) {echo "selected='selected'"; } ?> >Sport, competition...</option>
> </select>
> 
> Thansk,
> Pascal
> 

The best way to save values across pages is in the $_SESSION superglobal.


-- 
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#13907

Fromba pa <pppbbb10@gmail.com>
Date2014-06-19 10:22 -0700
Message-ID<f96c0de3-9853-455f-9e37-32e042ee8771@googlegroups.com>
In reply to#13906
I was just looking at this... using session_start and $_SESSION array...

Would it goes as:
document.getElementById("MyDropDown").value = '<?php echo $_SESSION['MyStoredValue']; ?>'

or

jQuery('#MyDropDown').val('<?php echo $_SESSION['MyStoredValue']; ?>');

thanks,
Pascal

[toc] | [prev] | [next] | [standalone]


#13908

FromJerry Stuckle <jstucklex@attglobal.net>
Date2014-06-19 16:45 -0400
Message-ID<lnvi64$rtb$1@dont-email.me>
In reply to#13907
On 6/19/2014 1:22 PM, ba pa wrote:
> I was just looking at this... using session_start and $_SESSION array...
> 
> Would it goes as:
> document.getElementById("MyDropDown").value = '<?php echo $_SESSION['MyStoredValue']; ?>'
> 
> or
> 
> jQuery('#MyDropDown').val('<?php echo $_SESSION['MyStoredValue']; ?>');
> 
> thanks,
> Pascal
> 

Pascal,

Pretty much.  Just a couple of things to remember:

session_start() must be called before ANY output to the client.  This
includes <!DOCTYPE...>, <HEAD...> and even blank space.

This must be done on EVERY page which uses $_SESSION values.

And, of course, you must store the value in the $_SESSION, also.

And you should check to see if the value is set before using it (i.e.
the first time through it may not be set); if not,  you should supply a
default value.

As for whether your jQuery code will work or not - try a javascript
newsgroup.  But the PHP code looks OK.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#13909

Fromba pa <pppbbb10@gmail.com>
Date2014-06-19 14:40 -0700
Message-ID<5d3db084-05b1-4038-ac5d-62ce2cb7c1ae@googlegroups.com>
In reply to#13908
Thanks Jerry for these useful advices, I should follow up on that implementing these

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.php


csiph-web