dcsimg
www.webdeveloper.com
Results 1 to 4 of 4

Thread: Using JavaScript To Control Forms - Part 2

Hybrid View

  1. #1
    Join Date
    Dec 2002
    Posts
    3

    Using JavaScript To Control Forms - Part 2

    I found this script and it works fine, now I have 1 question :

    I now use 0/1/2/3/4 see script

    <HTML>
    <HEAD>
    <TITLE>Required Select Field</TITLE>
    <SCRIPT>
    function validate() {
    if (mainform.Salary.options[0].selected) {
    alert('Please choose a Salary Range.');
    event.returnValue=false;
    }
    }
    </SCRIPT>
    </HEAD>
    <BODY>
    <FORM NAME="mainform" ACTION="http://hoohoo.ncsa.uiuc.edu/cgi-bin/post-query" METHOD="POST" onsubmit="validate();">
    <SELECT NAME="Salary">
    <OPTION VALUE="0" SELECTED>Salary Range</OPTION>
    <OPTION VALUE="1" >Less Than $10,000</OPTION>
    <OPTION VALUE="2" >$10,000-$20,000</OPTION>
    <OPTION VALUE="3" >$20,000-$30,000</OPTION>
    <OPTION VALUE="4" >More than $30,000</OPTION>
    </SELECT>
    <INPUT TYPE="SUBMIT">
    </FORM>
    </BODY>
    </HTML>

    Is it also possible to use A/B/C/D/E ??
    When I try it is not working.

    Thanks,
    Milcoi

  2. #2
    Join Date
    Nov 2002
    Posts
    4,473
    The VALUE attribute of the OPTION has nothing to do with it's SELECT array index. The SELECT array index is always an ordinal number that correlates to the OPTION's position in the HTML.

    If you wanted to index the array by specifying a constant (A/B/C/D/E), you should be able to add a NAME attribute to the OPTION tag:

    <OPTION NAME="A" ... >

    Then you could use this syntax to test it:

    if (mainform.Salary.options["A"].selected) {

    Nevermind. The syntax is supported in the W3C HTML 4.01 specification, but it doesn't work in IE 5.5.
    Last edited by gil davis; 12-11-2002 at 10:14 AM.

  3. #3
    Join Date
    Dec 2002
    Posts
    3
    Yep, just tested it and it doesn't work on IE5.5.

    Any 1 else have a idea??

    Thanks gil davis for you quick response.

    regards,
    Milcoi

  4. #4
    Join Date
    Dec 2002
    Posts
    3
    Any 1 a idea?

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