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
https://forums.phpfreaks.com/topic/54248-form-arrays-in-javascript/
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>

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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.