Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Aug 2011
    Posts
    44
    Thanks
    12
    Thanked 0 Times in 0 Posts

    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?

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,591
    Thanks
    78
    Thanked 4,385 Times in 4,350 Posts
    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.

  • Users who have thanked Old Pedant for this post:

    Chrys (09-02-2011)

  • #3
    New Coder
    Join Date
    Aug 2011
    Posts
    44
    Thanks
    12
    Thanked 0 Times in 0 Posts
    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?

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,591
    Thanks
    78
    Thanked 4,385 Times in 4,350 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •