0

Hi everyone i cant seem to get my drop down boxes to retain the data the user selected is this code right?

<select name="bap1" id="bap1" onchange='this.form.submit()' value="" >
      <option>Select One</option>
      <option value='Energy Efficient Cooking' <?php if($_POST['bap1'] == 'Energy Efficient Cooking') echo "selected"?>>Energy Efficient Cooking</option>

Tahnks in advance anyone!!

3
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by gpittingale
0

XHTML's a bit off:

<select name="bap1" id="bap1" onchange="this.form.submit()" value="" >
      <option>Select One</option>
      <option value="Energy Efficient Cooking" <?php if($_POST['bap1'] == 'Energy Efficient Cooking') echo "selected = \"selected\"";?>>Energy Efficient Cooking</option>

Should work - remember always double quote (") in XHTML - not interchangeable with (') as in JS/PHP. Also all attributes must have a value, therefore selected = "selected" and checked = "checked" should be used.
The attribute stuff is not important if you just want to get something working, but it may fail XHTML validation.

In addition, I would strongly advise that you 'clean' your $_POST variables. Otherwise, this should work... unless I missed something.

0

does a javascript submit refresh the page?

I ask, I dont use javascript much
'selected' is written by the server
if a javascript submit does not refresh the page selected will not be written,
I think..?

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.