0

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;" />
2
  • Why don't you use jQuery? Commented May 16, 2013 at 16:46
  • i dont even know javascript properly... i am first trying to understand javascript.. Commented May 17, 2013 at 4:32

1 Answer 1

2

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');
Sign up to request clarification or add additional context in comments.

1 Comment

sorry.. i was using a captialized 'V'. Changed it to lower letter and worked.Thanks...!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.