Hi,

I have a drop down
when a user selects a number from the drop down he sees those many textboxes with first name and last name

so if he selects 2 in the drop down then he sees 2 textboxes for first name and 2 textboxes for last name

so right now i am doing validation to see if he entered any values in the first name textboxes

if he didnt then fire an alert if he did then submit the form

i have this code but it doesnt work as my first name textboxes are blank can someone tell me what i am doing wrong

todd

function checkval()
{
var getncounting=document.frm1.nocount.value;
alert(getncounting);
for(i=0; i < getncounting; i++)
{
	 alert(i);
         var myElem = document.getElementById("txtfirstname" + i);
	if(myElem=="")
	{
	alert("enter something");
	}
}

hi,

is this the right way to check the contents in the textbox

var myElem = document.getElementById("txtfirstname" + i);

thanks,

todd

anyone with any ideas

todd

You need to access the element value by using the ' value ' property of the form element. The document.getElementById() function returns an Element , not it's value. Do something like:

var value = document.getElementById('txt' + i).value;
if(value == '')
{
  //do something
}

Just keep in mind that this kind of validation won't hold water if the user inserts multiple spaces in the field and submits the form.

Also the correct way of accessing form elements would be document.forms['frmName'].elements['elementName'].formProperty .

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.