jasonc Posted May 29, 2011 Share Posted May 29, 2011 For some reason this shows the error theValue is undefined theValue = document.getElementsByName('customerName').value; if (theValue.length > 0) { // do something } Link to comment https://forums.phpfreaks.com/topic/237762-how-to-get-length-of-a-form-field-using-name/ Share on other sites More sharing options...
jasonc Posted May 29, 2011 Author Share Posted May 29, 2011 this is my code now, but i can not work out how to actually check that the field have data or not as all fields get a green tick placed even if it is empty. function checkValidFormInput() { if (document.getElementsByName('customerName').value != '') { document.getElementById('customerNameImg').innerHTML = '<img alt="Valid" src="images/greenTick.png">'; } else { document.getElementById('customerNameImg').innerHTML = '<img alt="Invalid" src="images/redX.png">'; } if (document.getElementsByName('customerEmail').length > 0) { document.getElementById('customerEmailImg').innerHTML = '<img alt="Valid" src="images/greenTick.png">'; } else { document.getElementById('customerEmailImg').innerHTML = '<img alt="Invalid" src="images/redX.png">'; } } Link to comment https://forums.phpfreaks.com/topic/237762-how-to-get-length-of-a-form-field-using-name/#findComment-1221823 Share on other sites More sharing options...
sunfighter Posted May 29, 2011 Share Posted May 29, 2011 if you want to know how many use: var x=document.getElementsByName("customerName"); alert(x.length); If you want to know the value use: var x=document.getElementsByName("customerName"); alert(x[0].value); Link to comment https://forums.phpfreaks.com/topic/237762-how-to-get-length-of-a-form-field-using-name/#findComment-1221956 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.