Forum Moderators: open

Message Too Old, No Replies

Form Select Tag - Retaining Value

         

Loonius

1:28 am on Sep 27, 2004 (gmt 0)

10+ Year Member



Hi everyone. I'm in need of some expert help. I have a website where users can input information into a form and click on a "Preview" button to view the values they have entered. The preview appears below the form and works great!

My problem is this -- I've managed to figure out how to retain the information in standard text/text-area form fields (see below), but the "Select Tag" drop-down list reverts back to the default ("Select a City") once the preview button is selected. I can't figure out how to retain the drop-down list user selected option when the Preview button is hit. In the "Preview" area, the selected "option" is shown, but the value in the actual drop-down list does not remain.

I'm sure there is a "java" solution? Please! Any ideas? Below is an example of the form setup and preview function. Gracias!

///// FORM INPUT

<form name="customer" action="<?=$_SERVER['PHP_SELF']?>" method="post">

<input type="text" name="fname" value="<?=stripslashes($_POST['fname'])?>">
<input type="text" name="lname" value="<?=stripslashes($_POST['lname'])?>">

<SELECT name="area">
<OPTION value="None">Select a City</OPTION>
<OPTION value="1">London</option>
<OPTION value="2">Paris</OPTION>
<OPTION value="3">New York</OPTION>
</SELECT>

<input type="submit" value="Preview" name="preview">
<input type="submit" value="Submit" name="submit">
</form>

///// PHP CODE FOR PREVIEW

<?
if ($_POST['preview']) {

$locale = $_POST[area];
echo $locale;
echo stripslashes ($_POST['fname']);
echo stripslashes ($_POST['lname']);

}
?>

Rambo Tribble

4:17 am on Sep 27, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You will have to pass the select value from PHP to the new page. It might be easier to formulate your PHP to build the page with the appropriate option incorporating selected="selected", than to go through passing the variable to JavaScript and then using it to modify the selected property.

By the way, Java has next to nothing to do with JavaScript.