Jump to content

[SOLVED] option value remeber


TD

Recommended Posts

Hi, could please someone help me out, i'm thinking how to do this for about a day, and can't solve the prob.

 

When a user clicks on a car the option box selects what car has been choosed, after filling the form in and if he has forgotten to type some info, the script echos what did he forget, and the prob is, that the option value disappears.

How can i save the value or post it over?

 

Thanks ! P.S. sorry for my bad lang.

 

<?php

$t1=$_GET['t1'];

 

switch($t1)

{

case "1":

$t1v="selected='selected'";

$t2v="";

$t3v="";

break;

 

case "2":

$t1v="";

$t2v="selected='selected'";

$t3v="";

break;

 

case "3":

$t1v="";

$t2v="";

$t3v="selected='selected'";

break;

 

}

<form action="<? echo $_SERVER['PHP_SELF']; ?>" method="post">

<select name="auto">

<option value="Polo 1.4i" title="Polo 1.4i" <? echo $t1v?>>Polo 1.4i</option>

<option value="Golf 1.6i" title="Golf 1.6i" <? echo $t2v?>>Golf 1.6i</option>

<option value="Golf 1.9 TDI" title="Golf 1.9 TDI" <? echo $t3v?>>Golf 1.9 TDI</option>

</select>

</form>

Link to comment
Share on other sites

<?php

 

if($_GET['t1'] = "Polo 1.4i")  $isSelected  = "selected='selected'";

if($_GET['t1'] = "Golf 1.6i") $isSelected2 = "selected='selected'";

if($_GET['t1'] = "Golf 1.9 TDI") $isSelected3 = "selected='selected'";

 

?>

 

 

<form action="<? echo $_SERVER['PHP_SELF']; ?>" method="post">

<select name="auto">

<option value="Polo 1.4i" title="Polo 1.4i" <?=$isSelected?>>Polo 1.4i</option>

<option value="Golf 1.6i" title="Golf 1.6i" <?=$isSelected2?>>Golf 1.6i</option>

<option value="Golf 1.9 TDI" title="Golf 1.9 TDI" <?=$isSelected3?>>Golf 1.9 TDI</option>

</select>

</form>

Link to comment
Share on other sites

try this one

 

<?

<option value="Polo 1.4i" title="Polo 1.4i" <?=$isSelected?><? unset($isSelected) ?>>Polo 1.4i</option>

<option value="Golf 1.6i" title="Golf 1.6i" <?=$isSelected2?><? unset($isSelected2']) ?>>Golf 1.6i</option>

<option value="Golf 1.9 TDI" title="Golf 1.9 TDI" <?=$isSelected3?><? unset($isSelected3) ?>>Golf 1.9 TDI</option>

?>

Link to comment
Share on other sites

Error in operation I think "if($_GET['t1'] = "Polo 1.4i")"

 

<?php

 

if($_GET['t1'] == "Polo 1.4i")    $isSelected = "selected='selected'";

if($_GET['t1'] == "Golf 1.6i")    $isSelected2 = "selected='selected'";

if($_GET['t1'] == "Golf 1.9 TDI") $isSelected3 = "selected='selected'";

 

?>

 

 

<form action="<? echo $_SERVER['PHP_SELF']; ?>" method="post">

<select name="auto">

<option value="Polo 1.4i" title="Polo 1.4i" <?=$isSelected?>>Polo 1.4i</option>

<option value="Golf 1.6i" title="Golf 1.6i" <?=$isSelected2?>>Golf 1.6i</option>

<option value="Golf 1.9 TDI" title="Golf 1.9 TDI" <?=$isSelected3?>>Golf 1.9 TDI</option>

</select>

</form>

Link to comment
Share on other sites

allright the code looks now so and the option values work, but it just wont remember, when i hit submit form.

 

if($_GET['t1'] == "Polo 1.4i")      $isSelected  = "selected";

if($_GET['t1'] == "Golf 1.6i")    $isSelected2 = "selected";

if($_GET['t1'] == "Golf 1.9 TDI") $isSelected3 = "selected";

 

 

<option value="Polo 1.4i" title="Polo 1.4i" <?=$isSelected?>>Polo 1.4i</option>

<option value="Golf 1.6i" title="Golf 1.6i" <?=$isSelected2?>>Golf 1.6i</option>

<option value="Golf 1.9 TDI" title="Golf 1.9 TDI" <?=$isSelected3?>>Golf 1.9 TDI</option>

Link to comment
Share on other sites

Like I said before, use a SESSION or  COOKIE.  Did you try that?  HTML is a stateless protocol, so you have to make it remember something.

 

session_start(); //on very top of script for both scripts if separate

 

 

//on verification part

$_SESSION['myValue']=1; //1, 2, or 3

 

 

if ($_SESSION['myValue'])==1)

print "SELECTED";

//do the same for 2 or 3

 

Does that make sense?

 

Link to comment
Share on other sites

Am I missing something?  If I click a choice, get the errors, and then click back, the option I chose is always highlighted in the drop-down box.  I tested it twice for all of them.  That is exactly what you want, right?

 

I think it is the printed line under that you just forgot to change.

Link to comment
Share on other sites

Oh, I see.  I didn't actually wait that long to see the new form.

 

First, I need the actual code because the PHP is of no use already having been executed on the server.

 

Two ideas:  1. Just separate the form and the results. or

2. I can try to fix it, lol!

Link to comment
Share on other sites

This has changed the values to 1, 2, and 3, but this solves the specific problem I think.

 

Forgive me for not using a switch.  For some reason, I don't like them, lol.

 

Let me know if it works.

 

 

<body> 

 

<?PHP if (isset($_POST['auto']))

{

$selected1="";

$selected2="";

$selected3="";

 

if ($_POST['auto']==1)

$selected1="selected";

 

if ($_POST['auto']==2)

$selected2="selected";

 

if ($_POST['auto']==3)

$selected3="selected";

 

}

 

?>

 

<form action="form.php" method="post">

<table width="530px">

<tr>

  <td align="left" width="90px">Auto:</td>

  <td align="left" width="190px"><select name="auto" style="width:175px">

 

 

 

<option value="1" title="Polo 1.4i" <?PHP print "$selected1";?>>Polo 1.4i</option>

<option value="2" title="Golf 1.6i" <?PHP print "$selected2";?>>Golf 1.6i</option>

<option value="3" title="Golf 1.9 TDI" <?PHP print "$selected3";?>>Golf 1.9 TDI</option>

 

<input type="submit" name="submit" value="test" />

</TD>

</tr>

</table>

 

</form>

</BODY>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.