Jump to content

Form arrays in javascript


cesarcesar

Recommended Posts

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

 

<form method="POST" action="" name="this_form">
<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>

 

 

<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>

Link to comment
Share on other sites

Forgot submit

<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>

Link to comment
Share on other sites

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

 

<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>

 

 

<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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.