Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-02-2011, 04:50 AM   PM User | #1
Chrys
New Coder

 
Join Date: Aug 2011
Posts: 43
Thanks: 12
Thanked 0 Times in 0 Posts
Chrys is an unknown quantity at this point
Question Changing the default of a dropdown list depending on the url you are coming from

I have a form that I am using for several different pages as they are exactly the same... however at the top you must make a choice from the drop down box that then shows the appropriate fields to fill in.

Can I make the drop down default to a certain option depending on which page they are coming from?
Chrys is offline   Reply With Quote
Old 09-02-2011, 06:07 AM   PM User | #2
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,556
Thanks: 62
Thanked 4,055 Times in 4,024 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Certainly!

Unfortunately, you can't ask JavaScript what page the current page was reached from. You can ask PHP or ASP or JSP, but not JavaScript.

So if you aren't using PHP/ASP/JSP/etc., then the best you can do is "pass along" the page you are coming from.

Several ways to do that. Say the page with the <form> is "myform.html". Okay, so just call it from the various pages via "myform.html?from=contact" or "myform.html?from=orderform" or whatever.

And then you can look for that "from=" in the JS code and do the appropriate thing.

Another way would be to set a COOKIE in each page you come from and then look for the cookie in "myform.html".

Before I go further, though, *can* you use PHP/ASP/JSP for this page?
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Users who have thanked Old Pedant for this post:
Chrys (09-02-2011)
Old 09-02-2011, 06:22 AM   PM User | #3
Chrys
New Coder

 
Join Date: Aug 2011
Posts: 43
Thanks: 12
Thanked 0 Times in 0 Posts
Chrys is an unknown quantity at this point
Lets try the cookie method...

There is actually two places in this site I am doing this...
I figured out one because I believe that is the jsp you were refering to above.
I simply put the url to the form then "?forminput=4". This works because the page is .jsp. (this links to someone elses site)

However, the other instance is simply .html. Can we use cookies to do this?
Chrys is offline   Reply With Quote
Old 09-02-2011, 07:01 AM   PM User | #4
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,556
Thanks: 62
Thanked 4,055 Times in 4,024 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Ummm...cookies only work if all the pages are on the *SAME SITE*.

If you want to refer to this page from other sites, then I suggest you use the "?from=xxxx" method, instead. Or learn to use PHP?
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:23 AM.


Advertisement
Log in to turn off these ads.