SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Jul 2007
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    If statements checking for form completion?

    I'm writing code for a conference registration page, and having a friend write the php for it. I've never worked with html forms before by the way.
    How can I create an if statement that dosn't allow a viewer to submit their form if they have not filled out all the forms and also checked a confirmation text box? IE, an error box or page comes up if they have left a blank field and not clicked the text box. Hopefully I'm clear in what I'm talking about.
    Thanks!

  2. #2
    I'm not a human
    Join Date
    Aug 2006
    Location
    India
    Posts
    281
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi

    it's very simple .. just write a function in js to check the form fields (validation).. and just call the function on the submission of the form
    like,

    Code:
    <form name="form1" method=POST action="some page link" onSubmit="return check()">

    and the function check would have the validations as

    Code:
    function check()
    {
    
    	var eem   = document.form1.umail.value;
    	var cname = document.form1.compname.value;
    	var ph    = document.form1.phone.value;
    	
            if(eem == "" || ph == "" || cname == "")
    	{
    		alert("Please enter the values in all mandatory fields marked as *.");
    		return false;
    	}
    
    	if(!checkMailId(eem))
    	{
    		return false;
    	}
    	
    	for(var k=0; k<ph.length; k++)
    	{
    	  var alphaa = ph.charAt(k);
    	  var hh = alphaa.charCodeAt(0);
    	  if((hh > 42 && hh<46) || (hh > 47 && hh<58))
    	  {
    	  }
    	  else
    	  {
    		alert("Enter a valid Phone no (e.g: 1234567 (or) +91-011-4444444)");
    		return false;
    	  }
    	}	
    return true;
    }
    and for more function and tutorial on javascript visit javascript tutorial
    Regards,
    Vijay
    Follow me on twitter @vijaycbe
    World Holiday Calander || My Cricket Blog


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •