www.webdeveloper.com
Results 1 to 3 of 3

Thread: Cross browser problem - dynamic link update

  1. #1
    Join Date
    Apr 2011
    Posts
    2

    Cross browser problem - dynamic link update

    I have the following code to dynamically change a link based on a selection from a drop down list. If I use rounded brackets in the function for document.getElementByID the code works in IE but not in Firefox. If I use square brackets it works in Firefox but not in IE. I am a javascript novice and have copied the code from a forum changing it for my application. The code claimed to be cross browser.

    Code:
    <script type="text/javascript">
    function update(objS)
    {
    	document.getElementById('link').href = objS.options(objS.selectedIndex).value;
    }
    </script>
    <p class="drop1">Select PDF format:
    <select class="drop2" name="format"onchange="update(this)"> 
    ...selection list
    </select>
    <a STYLE="text-decoration:none" class="downbox" href="assets/first" name="link"> Free Download </a>

  2. #2
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    id and name are different tokens. If you are using getElementById(), then make sure your element has an id, not a name. A certain id must be unique on document.

    Another thing: the square brackets notation needs... square brackets
    Code:
    objS.options[objS.selectedIndex].value;
    ...
    <a STYLE="text-decoration:none" class="downbox" href="assets/first" id="link"> Free Download </a>
    And make sure that each of the OPTION elements has a value attribute indeed. IE<9 needs that.

  3. #3
    Join Date
    Apr 2011
    Posts
    2

    thanks

    thanks. works fine now.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles