Click to See Complete Forum and Search --> : Multi Seletec Box Validation problem


mukta
08-18-2006, 01:08 PM
HI

I have a field thats need to choose different option. Now i want to implement a validation script wheather user choose any one or not.

<SELECT NAME="myField[]" >

If i rename it to <SELECT NAME="myField" > it works . But when i'm giving that [] sign . I cant validate it.

Pls help me

A1ien51
08-18-2006, 01:13 PM
change

document.formName.elementName[]

to

document.forms[0].elements["elementName[]"]

[] in JavaScript stands for an array. And form elements can have arrays with multiple elements with the same name. Hence your issue.

Eric

mukta
08-18-2006, 01:44 PM
How can i check wheather its checked or not ?

// .length or .value or .selectedIndex none works here
if (document.forms[0].elements["JobCategory[]"])
{
alert("Please select Category");
//document.form.uname.focus();
return false;
}

// i'm checking others with this code
if (document.form.uname.value=='')
{
alert("Please enter name");
document.form.uname.focus();
return false;
}
how could i get that value ?

A1ien51
08-18-2006, 01:49 PM
document.forms[0].elements["JobCategory[]"] is a reference to the element object so add what you want to the end of it

document.forms[0].elements["JobCategory[]"].selectedIndex

document.forms[0].elements["JobCategory[]"].options[document.forms[0].elements["JobCategory[]"].selectedIndex].value



Eric

mukta
08-18-2006, 02:02 PM
I want to check wheather this <select name="JobCategory[]" multiple> field have been selected (at least one) or not . But i'm getting error "document.forms[0].elements["JobCategory[]"]" has no properties.