Book Section
-----
TY JavaScript 3rd Ed.
Teach Yourself JS 1.5
Teach Yourself DHTML
Teach Yourself JS 1.3
LLWW: JavaScript

General Section
-----
Discussion Forum
Articles / Tips
JavaScript Links
About the Author
Privacy Policy
Contact Me



Other Sites
-----
Website Workshop
JavaScript Weblog

JavaScript Workshop Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
Form Fields That Never Forget

 
Post new topic   Reply to topic    JSWorkshop Forum Index -> Server-Side Languages
View previous topic :: View next topic  
Author Message
Stormx
Member
Member


Joined: 19 May 2003
Posts: 19

PostPosted: Fri Aug 22, 2003 1:12 pm    Post subject: Form Fields That Never Forget Reply with quote

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
View user's profile Send private message
phil karras
Senior Member
Senior Member


Joined: 15 Jul 2002
Posts: 1776
Location: MD

PostPosted: Mon Aug 25, 2003 11:13 am    Post subject: Reply with quote

If you are using PHP then you'll have to read in all the input field values in the PHP section, do what you want to do, then build up the page using PHP and fill the values for the fields back in.
_________________
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
View user's profile Send private message Visit poster's website
Stormx
Member
Member


Joined: 19 May 2003
Posts: 19

PostPosted: Tue Aug 26, 2003 11:08 am    Post subject: Eh? Reply with quote

Nononono! I want it to remeber what was imputed last time when the user comes back!
Back to top
View user's profile Send private message
sohnee
Senior Member
Senior Member


Joined: 17 Jul 2002
Posts: 2077
Location: UK

PostPosted: Wed Aug 27, 2003 12:39 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
phil karras
Senior Member
Senior Member


Joined: 15 Jul 2002
Posts: 1776
Location: MD

PostPosted: Wed Aug 27, 2003 7:10 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    JSWorkshop Forum Index -> Server-Side Languages All times are GMT - 7 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2002 phpBB Group
(c) 1997-2002 Starling Technologies and Michael Moncur. Portions (c) Sams Publishing.