Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

check field is blank

Status
Not open for further replies.

dude333

Programmer
Feb 5, 2004
11
GB
Hi,

Can anyone tell me how I can check to see if this form field is blank on submit:

<input type='hidden' name='conn[]' id='cs' value=' '>

The problem is that javascript won't seem to allow the [] on the end of conn in the name.

ie this: theForm.conn[].value ==""; produces a syntax error.

i have tried this aswell:
var id=document.formname.cs;
document.getElementById(id).value="";

this produces an error that says object does'nt support this property .

I can't remove the [] from the end of the field name cos this is required for some server side processing.

Anyone got any ideas?

Cheers.
 
Javascript doesn't seem to like HTML array syntax. The [] syntax is used for javascript arrays as well, so javascript probably assumes you're accessing a javascript array, when this is not the case. Here is the workaround:
Code:
blah = theForm.elements['conn[]'];
alert(blah.value);

-kaht

banghead.gif
 
sort of OT, but i have heard so many people say that php requires this odd naming convention...i'll never understand why php can't seem to allow the same "normal" (non-bracketed) field names that EVERY other server-side language on the planet accepts...

=========================================================
-jeff
try { succeed(); } catch(E) { tryAgain(); }
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top