Find services - Debt Consolidation - Debt Consolidation - Image Hosting - Debt Consolidation

PDA

View Full Version : debug this code : validate form


googlehelper
Feb 20th 2009, 12:34 am
<!-- JavaScript -->
<script type='text/javascript'>
function validate(form)
{
var flen = document.getElementById('F1').value.length;
var llen = document.getElementById('f2').value.length;

if (flen<3||llen<1)
{
alert('Error : Enter a valid Name.Enter your initials if you dont have a last name');
return false;
}
return true;

}
</script>
<!-- JavaScript End-->


<form id='form' name='join' class='joinform' enctype='multipart/form-data'
method='post' onsubmit='return(validate(this));' autocomplete='off' >

<ul>
<li id='fg0'>
<label class='desc' >Name<span class='req'>*</span></label>
<span><select id='F0' name='sex' tabindex='2' >
<option value='0' selected='selected'>&nbsp;Title&nbsp;&nbsp;&nbsp;&nbsp;</option>
<option value='m'>Mr</option> <option value='f'>Ms</option>
</select>
<label for='F1'>Title</label></span>
<span><input id='F1' name='fnam' type='text' maxlength='15' size='8' tabindex='3' />
<label for='F1'>First</label></span>
<span><input id='F2' name='lnam' type='text' maxlength='15' size='12' tabindex='4' />
<label for='F2'>Last</label></span>
</li>
........................................
.................................


Debug this code i dont get any alerts

gnp
Feb 20th 2009, 5:53 am
The id on one element is F2 but you try to access it as f2.

Javascript is case sensitive so it fails.

this will work
var llen = document.getElementById('F2').value.length;

regards

googlehelper
Feb 20th 2009, 10:52 am
i dont know what was the error but when i retyped the dito code line by line it worked

anyways thanks i know that(case sensitive)

gnp
Feb 20th 2009, 12:45 pm
if you notice on my post (and your original code)

you where retrieving the element using a small-case f instead of the capital F (which you used for the id of the element..)

that is why i mentioned it ... it was the actual error..

glad you finally got it working :)