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
https://forums.phpfreaks.com/topic/60499-solved-option-value-remeber/
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>

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>

?>

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>

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>

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?

 

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.

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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.