...

View Full Version : Changing the default of a dropdown list depending on the url you are coming from



Chrys
09-02-2011, 05:50 AM
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?

Old Pedant
09-02-2011, 07:07 AM
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?

Chrys
09-02-2011, 07:22 AM
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?

Old Pedant
09-02-2011, 08:01 AM
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?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum