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 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Aug 2002
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Passing value taken from a form field to another form thru a hyperlink.

    Hi to all,

    A newbie here..

    How to get the value (ie. from a drop down list called 'select') and pass it thru a hyperlink to another page?

    Thanks in advance!

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    <a href="#" onclick="location.href='page2.htm?'+document.yourFormName.select.options[document.yourFormName.selectedIndex].value">Page 2</a>


    then in your page 2: (assuming you have only one parameter passed in the URL)

    if (location.search.length>1)
    alert(location.search.substring(1))
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #3
    Senior Coder joh6nn's Avatar
    Join Date
    Jun 2002
    Location
    72° W. 48' 57" , 41° N. 32' 04"
    Posts
    1,887
    Thanks
    0
    Thanked 1 Time in 1 Post
    <A HREF="thenextpage.htm" onclick="theFunction(); return false;">click click</A>

    <script>
    function theFunction() {
    var selected = document.theForm.theSelectBox.options[document.theForm.theSelectBox.selectedIndex].value;
    window.location = "thenextpage?" + selected;
    }
    </script>


    that will pass the value to the next page. it does this first finding the selected value. then, it adds the selected value to the end of the next page's URL, using the question mark (?).

    on the next page, you use the following to retrieve the value:

    <script>
    if ( window.location.search ) {
    var value = window.location.search.slice(1);
    }
    </script>

    what that does, is take the url, look for the search string ( which is the ?, and everything after it ). if the search string exists, then it strips it of the ?, and assigns what's left to the variable value.
    bluemood | devedge | devmo | MS Dev Library | WebMonkey | the Guide

    i am a loser geek, crazy with an evil streak,
    yes i do believe there is a violent thing inside of me.

  • #4
    New to the CF scene
    Join Date
    Aug 2002
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks to the above 2 replies..Actually i intend to let the customer choose the color of the prod they intend to buy, thus the purpose of the list box.


    I tried this:

    <a href="http://www.sitename.com/cf/add.cfm?userid=1111111&product=12+roses+document.Prod1.select.options[document.Prod1.selectedIndex]&price=70.00">Add to Cart</a>

    But after passing the values to the 2nd page(payment gateway), what was displayed is:

    "12 roses document.Prod1.select.options[document.Prod1.selectedIndex].value"

    How do I let it display:
    "12 roses Red"

  • #5
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    <a href="#" onclick="location.href='http://www.sitename.com/cf/add.cfm?userid=1111111&price=70.00&product=12%20roses%20'+document.Prod1.select.options[document.Prod1.selectedIndex].value">Add to Cart</a>

    i supposed you have the server-side code handle the retrieval of the query string, so location.search is not needed.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #6
    Senior Coder joh6nn's Avatar
    Join Date
    Jun 2002
    Location
    72° W. 48' 57" , 41° N. 32' 04"
    Posts
    1,887
    Thanks
    0
    Thanked 1 Time in 1 Post
    assign the value to a variable, and then pass the variable. eg,

    <A HREF="thenextpage.htm" onclick="theFunction(); return false;">click click</A>

    <script>
    function theFunction() {
    var selected = document.theForm.theSelectBox.options[document.theForm.theSelectBox.selectedIndex].value;
    window.location = "thenextpage?" + selected;
    }
    </script>

    by trying to pass this:
    document.theForm.theSelectBox.options[document.theForm.theSelectBox.selectedIndex].value
    you're passing a reference, that won't exist on the next page. the form is on this page, when the next page loads, how is it going to reference that form? that's why you pull the value out of that reference, and then build the value into the url.

    also don't write your link like this:
    <A HREF="#" onClick="....">

    this is a very common, very popular form, but there are good reasons not to do that. suppose your user has javascript turned off. if they click on that link, they'll be brought to the top of the page. if they had to scroll down at all in order to get to that link, they will be ticked off

    <EDIT>
    or what glenn said. whatever.
    </EDIT>
    bluemood | devedge | devmo | MS Dev Library | WebMonkey | the Guide

    i am a loser geek, crazy with an evil streak,
    yes i do believe there is a violent thing inside of me.


  •  

    Posting Permissions

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