Results 1 to 3 of 3

Thread: Calling a function within an option tag

  1. #1
    Join Date
    Nov 2002
    Norwood, MA

    Calling a function within an option tag

    Hello world!

    I'm trying to figure out, but I can't, how to call a JS function that's defined in the header of my page within the OPTION tag of a SELECT tag.

    What's happening is that as the page loads I'm pulling the options together with a SQL statement and if the statement yields one record I want the form to select the value and run a JS that pre-populates other fields in the form.

    When the list yields multiple names, then they just click and the JS runs with an onclick event handler. However, when the list yields one item, none of the mouse or keyboard event handlers would apply to get the JS to happen. I tried just popping it in as an "onload" within the OPTION tag, but that didn't work either. Is there another way to do this?

    I'm a bit stuck on where the JS is called because I'm interspersing with VBscript and SQL statements.

    Thanks in advance!!!!!


  2. #2
    Join Date
    Apr 2009
    Try with onFocus...

  3. #3
    Join Date
    Dec 2005
    Events will not trigger within an <option> tag in MSIE.
    They will trigger in FF.

    For MSIE, you will need to put the action trigger in the <select> tag
    and decide what to do bases upon the option value passed to the function.

    Simple example:
    <title> Select Box Triggers</title>
    Event triggers in FF but not MSIE
    <select id="SBox1">
     <option valu=""></option>
     <option value="1" onclick="alert(this.value)">One</option>
     <option value="2" onclick="alert(this.value)">Two</option>
     <option value="3" onclick="alert(this.value)">Three</option>
     <option value="4" onclick="alert(this.value)">Four</option>
     <option value="5" onclick="alert(this.value)">Five</option>
    Event triggers in FF and MSIE
    <select id="SBox2" onchange="alert(this.value)">
     <option valu=""></option>
     <option value="1">One</option>
     <option value="2">Two</option>
     <option value="3">Three</option>
     <option value="4">Four</option>
     <option value="5">Five</option>
    Last edited by JMRKER; 09-25-2009 at 11:48 PM. Reason: Provided example code

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