reloading drop downs with selected<

liunx

Guest
I have a program that checks for blank fields within a form. If it finds one, it reloads the page and asks the user to fill in the fields they missed. However, I can't get the drop down to retain whatever the user selected, it goes back to its default. Is there a way to remember what the user selected after the page reloads? Thanks!

CODE:

<p>* How many records have you sold?
<select name='sold' class='input' value='$sold'>
<option value='0-50'>0-50
<option value='50-100'>50-100
<option value='100-250'>100-250
<option value='250-500'>250-500
<option value='500-1000'>500-1000
<option value='1000-2000'>1000-2000
<option value='2000+'>2000+
</select>
</p>php?


<p>* How many records have you sold?
<select name='sold' class='input'>
<option value='0-50'<?php echo ($sold=='0-50'?' selected':''); ?>>0-50
<option value='50-100'<?php echo ($sold=='0-50'?' selected':''); ?>>50-100
<option value='100-250'<?php echo ($sold=='100-250'?' selected':''); ?>>100-250
<option value='250-500'<?php echo ($sold=='250-500'?' selected':''); ?>>250-500
<option value='500-1000'<?php echo ($sold=='500-1000'?' selected':''); ?>>500-1000
<option value='1000-2000'<?php echo ($sold=='1000-2000'?' selected':''); ?>>1000-2000
<option value='2000+'<?php echo ($sold=='2000+'?' selected':''); ?>>2000+
</select>
</p>actually that would be

<p>* How many records have you sold?
<select name='sold' class='input'>
<option value='0-50'<?php echo ($sold=='0-50')?' selected':''; ?>>0-50
<option value='50-100'<?php echo ($sold=='0-50')?' selected':''; ?>>50-100
<option value='100-250'<?php echo ($sold=='100-250')?' selected':''; ?>>100-250
<option value='250-500'<?php echo ($sold=='250-500')?' selected':''; ?>>250-500
<option value='500-1000'<?php echo ($sold=='500-1000')?' selected':''; ?>>500-1000
<option value='1000-2000'<?php echo ($sold=='1000-2000')?' selected':''; ?>>1000-2000
<option value='2000+'<?php echo ($sold=='2000+')?' selected':''; ?>>2000+
</select>
</p>scoutt, you made me doubt of my own knowlegde!
so i check on php.net/echo and beleive what?
you don't even need those ()!well it has nothing to do with echo. doing a compare is always best to use (). I didn't add them because of the echo, I added them because they looked in the wrong spot for the terinary (sp) comparei didn't know where to find that thing in the doc, so i look in the echo page... but now that i think about it, i use it everywhere!


<!-- m --><a class="postlink" href="http://ca2.php.net/language.operators">http://ca2.php.net/language.operators</a><!-- m -->

The third group is the ternary operator: ?:. It should be used to select between two expressions depending on a third one, rather than to select two sentences or paths of execution. Surrounding ternary expressions with parentheses is a very good idea.yeah like this

$var = ($sold=='0-50')?' selected':'';

not like this

($sold=='0-50'?' selected':'');

I also believe that will error outis the ternary expression the whole thing or just the evaluation part?

test.php
<?php
$a = 'a';
echo $a=='a'?'c':'d';
echo ($a=='a')?'e':'f';
echo ($a=='a'?'g':'h');
?>

output: ceg
with no error.interesting, I have never seen it this way

echo $a=='a'?'c':'d';
echo ($a=='a'?'g':'h');

I ahve always seen it this way

echo ($a=='a')?'e':'f';


or like this


$var = ($a=='a')?'e':'f';
echo $var;

curious if you do it that way on one of yours will it work? I am thinking that the echo is making it work.<?php
$a = 'a';
$var = $a=='a'?'c':'d';
echo $var;
$var = ($a=='a')?'e':'f';
echo $var;
$var = ($a=='a'?'g':'h');
echo $var;
?>

still output cegcool, I guess it doesn't matter than. :)
 
Top