Pradeep
Pradeep

Reputation: 1223

Accessing input fields not working

i have 8 text fields and two textareas in my form.i am trying to access all of them and check whether they are empty or not.But somehow the javascript i wrote is not working.here is the code:

javascript:

function textboxes(formobj) 
{              
   var ip = formobj.getElementsByTagName('input');

   for(var i=0; i<ip.length; i++)
   {
    if(ip[i].value == "")
    {
        alert("empty field");
        ip[i].focus();
        return false;
    }
   }  
}

The id of the form is 'genform' and this is passed as an arguement to the above javascript code while the button is clikced :

HTML:

<input type="submit" name="submit" value="Generate Questions" 
 onclick="return textboxes('genform'); return false;" />

Upvotes: 0

Views: 71

Answers (1)

Frison Alexander
Frison Alexander

Reputation: 3256

This would be a lot easier with jQuery. Thats for another day :)

The onclick event handler passes the text 'genform' to your function. You have to grab the DOM element from this.

 var ip =  document.getElementById(formobj).getElementsByTagName('input');

Upvotes: 2

Related Questions