| View previous topic :: View next topic |
| Author |
Message |
Stormx Member

Joined: 19 May 2003 Posts: 19
|
Posted: Fri Aug 22, 2003 1:12 pm Post subject: Form Fields That Never Forget |
|
|
OK, say we have a drop down list, and the user can select an option and click "go". When the user comes back to the page, how can i make the browser remember what the user chose. Is there a way with cookies.
Because i'm unsing a PHP design, the code loops untill it reaches the amout a variable contains. E.G...
<?
$somevar = 5;
echo ("<select size=\"$somevar\">");
$temp = 0;
while ( $temp < $somevar ) {
echo ("<option value=\"index.php?id=$temp\">This Is Option $temp</option>");
$temp++;
}
?>
Theres a lot more code than that. I was thinking mabey loading another variable from a cookie and then adding the "SELECTED" attribute when $temp is the same as the variable in the cookie.
Please forgive me if this is in the wrong forum. I don't know if we would do the cookie in HTML, JavaScript, PHP, or whatnot. Furthermore, I am open for suggestions of other ways to store the Data. This form will be on "enter" page |
|
| Back to top |
|
 |
phil karras Senior Member

Joined: 15 Jul 2002 Posts: 1776 Location: MD
|
|
| Back to top |
|
 |
Stormx Member

Joined: 19 May 2003 Posts: 19
|
Posted: Tue Aug 26, 2003 11:08 am Post subject: Eh? |
|
|
| Nononono! I want it to remeber what was imputed last time when the user comes back! |
|
| Back to top |
|
 |
sohnee Senior Member

Joined: 17 Jul 2002 Posts: 2077 Location: UK
|
Posted: Wed Aug 27, 2003 12:39 am Post subject: |
|
|
PHP has a very simple setcookie() function, just pass in
| Code: | | setcookie( "selected", "optionname", time()+60*60*24*365, "/", "domain.com", 0); |
Then it is just a case of adding an if statement to the loop that writes the options
| Code: | ...something about print "<option value='blah'";
if ( isset( $selected ) ) {
if ( $option == $selected) {
print "selected";
}
}
...something to finish it print ">Option1</option>" |
|
|
| Back to top |
|
 |
phil karras Senior Member

Joined: 15 Jul 2002 Posts: 1776 Location: MD
|
Posted: Wed Aug 27, 2003 7:10 pm Post subject: |
|
|
The bottom line is that once you post to a server-side script, the page that posted, no longer exists, and so there is no "memory" you have to save the values some way and re-build the page with your server-side script.
Cookie, vars, whatever. The other way is with a "hidden" frame which has the values on the client side and the next page that opens in the "other" frame can then get the values put in the "hidden" frame.
This hidden-frame method is the one I have used for my shopping cart. The code for the hidden-frame shopping cart is on my cs.yrex site. _________________ Phil K
Circle Software Consulting
Test website: http://cs.yrex.com/
Guidelines for Posting: http://www.jsworkshop.com/posting.html
IHBAAA = It Has Been Asked And Answered
KISS: http://www.jsworkshop.com/bb/viewtopic.php?t=508 |
|
| Back to top |
|
 |
|