Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-08-2008, 02:08 PM   PM User | #1
orit_v2003
New Coder

 
Join Date: Nov 2006
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
orit_v2003 is an unknown quantity at this point
Help with simple js Form Validation

Hi,
I have a simple form.
I checked if the mail is valid and if they filled the name field.

The problem is that i want to let the client to fill their phone or mobile number.
I did a flag but it doesn't work. something is realy wrong with the code and i don't know why?

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>

<!-- Generated by responder.co.il -->
<script language="JavaScript" type="text/javascript">
<!--
function responder_validation()
{
    var flag = false
    var rspform = document.getElementById("rspform");
    var listitems= rspform.getElementsByTagName("input");



for (a=0;a<listitems.length;a++)
{ switch (listitems[a].name)
  {

	case 'fields[subscribers_email]':	var reEmail = /^[-\w\d\.]+@[-\w\d\.]+\.[-\w\d\.]+$/;
										if(listitems[a].value == "")
											{   alert("please fill in your email");listitems[a].focus();return false;}
										if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(listitems[a].value)))
											{   alert("your email is not correct.");listitems[a].focus();return false;}
										break;
	case "fields[subscribers_name]":			if(listitems[a].value == "")
											{   alert("Please fill in your name");listitems[a].focus();return false;}
										break;



	case "fields[phone]":			if(listitems[a].value != "")
											{   flag=true;}							

	case "fields[mobile]":			if(listitems[a].value != "")
											{  flag=true;}

										
	case "fields[subject]":		
									if(listitems[a].value == "")
										{   alert("Please right the subject");listitems[a].focus();return false;}
								break;
											

  }
}
					
					
if (flag==false)
{
	alert("Please fill in your Home phone or mobile number");
	return false;

}

	}
				//-->
				</script>

</head>

<body>
    <form action="http://cp.responder.co.il/subscribe.php" method="post" onSubmit="return responder_validation()" id="rspform" >				
    <table id="tform" align="right" cellpadding="0" cellspacing="5" border="0">
        <tr>
            <td id="label">first name:</td>
            <td id="control"><input id="inputText" name="fields[subscribers_name]" type="text" maxlength="20"></td>
        </tr>
        <tr>
            <td id="label">family name:</td>
            <td id="control"><input id="inputText" name="fields[family_name]" type="text" maxlength="30" /></td>
        </tr>
        <tr>
            <td id="label">email:</td>
            <td id="control"><input id="inputText" name="fields[subscribers_email]" type="text" maxlength="50" /></td>
        </tr>

        <tr>
            <td id="label">phone:</td>
            <td id="control"><input id="inputPhone" name="fields[phone]" type="text" maxlength="20" /> </td>
        </tr>

        <tr>
            <td id="label">mobile:</td>
            <td id="control"><input id="inputPhone" name="fields[mobile]" type="text" maxlength="20" /> </td>
        </tr>

        <tr>
            <td id="label">subject:</td>
            <td id="control"><input id="inputText" name="fields[subject]" type="text" maxlength="50" /></td>
        </tr>

        <tr>
            <td id="label">comments:</td>
            <td id="control"><textarea id="inputTextArea" name="fields[comments]"></textarea></td>
        </tr>
        <tr>
            <td id="label"></td>
            <td id="control"><input type="submit" value="send">  

            <input type="reset" name="clear" value="clear" id="inputButton"></td>
        </tr>
    </table>

<!--<input type="hidden" name="form_id" value="">-->
</form>
</body>
</html>
There is also problem with the focus.

Help...
orit_v2003 is offline   Reply With Quote
Old 10-08-2008, 03:46 PM   PM User | #2
shyam
Senior Coder

 
shyam's Avatar
 
Join Date: Jul 2005
Posts: 1,563
Thanks: 2
Thanked 163 Times in 160 Posts
shyam will become famous soon enough
the missing breaks for fields[phone] and fields[mobile]
__________________
You never have to change anything you got up in the middle of the night to write. -- Saul Bellow
shyam is offline   Reply With Quote
Old 10-10-2008, 10:50 AM   PM User | #3
orit_v2003
New Coder

 
Join Date: Nov 2006
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
orit_v2003 is an unknown quantity at this point
thank you very very much

It was a stupid mistake and i didn't see it.
I was looking on it for 3 days.
orit_v2003 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:04 PM.


Advertisement
Log in to turn off these ads.