How to identify Combobox control (HTML)

Status
Not open for further replies.

anuj_web

New Member
Messages
145
Reaction score
0
Points
0
Hi...


How can i identify the type of a combobox element..
like the text box is identified by the type "text"

I got that one....
but when I try to check the values of all the comboboxes it does not work

Code:
function Validate(theform)
{
var elem = document.getElementById('theform').elements;
for(var i = 0; i < elem.length; i++)
{
if(elem[i].type="select-one" && elem[i].value="")
{
alert('You have not selected all required Parameters');
theform.action="";
theform.submit;
}
else
{
theform.action="Search.php";
theform.submit;
}
} 

}

I cannot access the control type and its value in this code and hence ...I think this is why the code does not give the output ... i.e no alert is generated

thanks
 
Last edited:

woiwky

New Member
Messages
390
Reaction score
0
Points
0
You're using a single = instead of a double. So you need to change

if(elem.type="select-one" && elem.value="")

to

if(elem.type=="select-one" && elem.value=="")
 

marshian

New Member
Messages
526
Reaction score
9
Points
0
I think that's right, but for the sake of making your code readable, use
if((elem.type=="select-one") && elem.value=="")
 

anuj_web

New Member
Messages
145
Reaction score
0
Points
0
Hi..

it does not work even after that
:(
Code:
function Validate(theform)
{
var elem = document.getElementById('theform').elements;
for(var i = 0; i < elem.length; i++)
{
if(elem[i].type=="select-one" && elem[i].value=="")
{
alert('You have not selected all required Parameters');
theform.action="";
theform.submit;
}
else
{
theform.action="Search.php";
theform.submit;
}
} 
}

still even the alert does not come up.....

i think i am faulting with the "form" passing
wat should i pass to the function "validate" as as argument ??
 

woiwky

New Member
Messages
390
Reaction score
0
Points
0
If the call is in the onsubmit event of your form element, it should be Validate(this). That is,

<form onsubmit="Validate(this);">

Also, you can use theform.elements instead of document.getElementById('theform').elements if the form object is being passed correctly.
 

anuj_web

New Member
Messages
145
Reaction score
0
Points
0
It works now thanks...i feel the problem was with the "form" passing itself
 
Status
Not open for further replies.
Top