SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict
    Join Date
    Jun 2005
    Posts
    196
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Form arrays in javascript

    Why wont this work? checkFields() iF statment is failing. The select must be set to multiple. Thanks.

    Code:
    <form method="POST" action="" name="this_form" onSubmit="return checkFields();">
    	<select name="this_select[]" multiple>
    		<option value="ts1">ts1</option>
    		<option value="ts2">ts2</option>
    		<option value="ts3">ts3</option>
    		<option value="ts4">ts4</option>
    	</select>
    </form>

    Code:
    <script language="Javascript">
    <!--
    function checkFields(){
    	var errormsg = "";
    	if (document.this_form.this_select.value == "") { var errormsg = errormsg + "Please Select an Value.\n\r"; }
    	if (errormsg != "") { alert(errormsg); return false; }
    }
    //-->
    </script>

  2. #2
    SitePoint Addict
    Join Date
    Jun 2005
    Posts
    196
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ........

  3. #3
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It works fine for me. Which browser(s) is it not working in?

    BTW, the language attribute is obsolete. You should use the type attribute instead.
    Code:
    <script type="text/javascript">
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  4. #4
    SitePoint Addict
    Join Date
    Jun 2005
    Posts
    196
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    solution:
    Code:
    document.this_form.elements['this_select[]'].value

  5. #5
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, that's the solution. It seems that you changed the name of the select element at some point and I didn't notice. As you can see, it makes a difference.
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  6. #6
    SitePoint Addict
    Join Date
    Jun 2005
    Posts
    196
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes it does. i have also taken your advice on the type attribute. thanks/


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
  •