Click to See Complete Forum and Search --> : Form validation with odd 'name' fields


jmr5787
03-14-2005, 11:38 AM
I have a form that links into our company database when submitted. I have found that the field name, in order to make it transfer successfully into the database, has to remain fixed (a mixture of numbers and upper and lower case letters). But when I run the validation, any time I add these oddly named fields to the validation process, it breaks the entire validation.

For instance, in my form posted here, validation works perfectly if I remove the 'Product Serial Number' validation script, but as soon as I add it back in, the entire validation breaks. Any ideas?

Thanks!

<script language="javascript">
function formCheck() {
if (document.reg.name.value == "")
{
alert("Please enter your Name.");
return false;
}

if (document.reg.company.value == "")
{
alert("Please enter your Company.");
return false;
}

if (document.reg.phone.value == "")
{
alert("Please enter your Phone Number.");
return false;
}

if (document.reg.email.value == "")
{
alert("Please enter your Email Address.");
return false;
}

if (document.reg.00N30000000hRO7.value == "")
{
alert("Please enter your Product Serial Number.");
return false;
}

return true;
}
</script>


<form name="reg" action="http://www.salesforce.com/servlet/servlet.WebToCase?encoding=UTF-8" method="POST" onSubmit="return formCheck();">


<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="30%"><font color="red">*</font>Contact Name:</td>
<td width="2%">&nbsp;</td>
<td width="68%"><input name="name" id="name" type="text" size=20 maxlength=80></td>
</tr>
<tr>
<td><font color="red">*</font>Company:</td>
<td>&nbsp;</td>
<td><input name="company" id="company" type="text" size=20 maxlength=80></td>
</tr>

<tr>
<td><font color="red">*</font>Phone:</td>
<td>&nbsp;</td>
<td><input name="phone" id="phone" type="text" size=20 maxlength=40></td>
</tr>
<tr>
<td><font color="red">*</font>Email:</td>
<td>&nbsp;</td>
<td><input name="email" id="email" type="text" size=20 maxlength=80></td>
</tr>
<tr>
<td><font color="red">*</font>Product Serial Number:</td>
<td>&nbsp;</td>
<td><input name="00N30000000hRO7" id="00N30000000hRO7" type="text" size=20 maxlength=80>&nbsp;(ex. 150-408113)</td>
</tr>
</table>
<br>

<input type="submit" name="submit" value="Submit Request">

</form>

Pittimann
03-14-2005, 11:43 AM
Hi!

Such names are not valid! Anyway, use something like:

if (document.reg['00N30000000hRO7'].value == "")

It would be better to convince the people in charge to let the field names begin with a letter.

Cheers - Pit

jmr5787
03-14-2005, 12:00 PM
Thanks - this seems to work well.

Pittimann
03-14-2005, 12:08 PM
Hi!

Nice. :p You're welcome.

Cheers - Pit

felgall
03-14-2005, 02:16 PM
Field names are supposed to start with a letter so even though the code works now in one browser doesn't mean that it will work in other browsers or future versions of the same browser.

Pittimann
03-14-2005, 02:30 PM
Hi!Originally posted by myself
Such names are not valid!
It would be better to convince the people in charge to let the field names begin with a letter.felgall, English is a foreign language to me, but didn't the above suffice?

Pit

herodote92
03-14-2005, 03:13 PM
[quote]
Field names are supposed to start with a letter
[unquote]

Hmm, sorry to interfere, but Flanagan says that an identifier should begin with a letter OR an _underscore OR (since JS 1.1) a $dollar symbol.

He says these are legal identifiers:
i
variable_name
v13
_dummy
$str

All this provided you don't use reserved keywords, of course.

Pittimann
03-14-2005, 03:19 PM
Hi herodote92!

Neither Flanagan, nor you or me are the W3C (http://www.w3.org/TR/html401/types.html#type-cdata).

Cheers - Pit