Results 1 to 2 of 2

Thread: Accessing A javascript variable in HTML

  1. #1
    Join Date
    Mar 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Accessing A javascript variable in HTML

    Hi All,

    I have two Select Boxes on my web page, 2nd being populated based on selection of first select box.

    Now I am suppose to get the selected value of 2nd Select and put it in a link i.e. <a href='abc.html?id=<2nd select box value>' .

    I can get the selected value using Javascript with the following code:

    2ndid = form.2ndodf.options[form.2ndodf.options.selectedIndex].value;


    where 2ndid is a global javascript variable.


    How I can use this variable into <a href> tag.

    2nd idea may be to use PhP but I am unable to do so.

    Any suggestions please.

    Thanks and regards,

  2. #2
    Join Date
    Jun 2008
    Posts
    589
    Thanks
    13
    Thanked 54 Times in 54 Posts
    Blog Entries
    1

    Default

    Perhaps this:

    Code:
    <select onchange="document.getElementById('myLink').href = this.options[this.options.selectedIndex].value">
    <option value="http://www.google.com/" selected>Google</option>
    <option value="http://www.yahoo.com/">Yahoo</option>
    <option value="http://www.lycos.com/">Lycos</option>
    </select>
    <a id="myLink" href="http://www.google.com/">GO!</a>

Bookmarks

Posting Permissions

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