JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 19th, 2013, 12:13 AM
chrisjchrisj chrisjchrisj is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 44 chrisjchrisj User rank is Sergeant (500 - 2000 Reputation Level)chrisjchrisj User rank is Sergeant (500 - 2000 Reputation Level)chrisjchrisj User rank is Sergeant (500 - 2000 Reputation Level)chrisjchrisj User rank is Sergeant (500 - 2000 Reputation Level)chrisjchrisj User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 5 h 29 m 56 sec
Reputation Power: 15
Making Contact_Name a mandatory Form field

I have this Form that works successfully (I know it's not state-of-the-art).
I simply want to add code to make Contact Name field mandatory. Can you help me?

Code:
<script type="text/javascript">
function checkemail(){
var str=document.myform.email_address.value;
var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
if (filter.test(str))
testresults=true;
else {
alert("Please input a valid email address!");
return false;
}
if(document.myform.agree.checked!=1) {
alert("Please check the box to agree to the Terms.");
return false;
}
if(document.myform.ans.value.toLowerCase()!="white") {
alert("Please answer security question correctly: Black or White?");
return false;
}
return true;
}
</script>

Reply With Quote
  #2  
Old March 19th, 2013, 04:07 AM
paulh1983 paulh1983 is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Dec 2004
Posts: 2,324 paulh1983 User rank is First Lieutenant (10000 - 20000 Reputation Level)paulh1983 User rank is First Lieutenant (10000 - 20000 Reputation Level)paulh1983 User rank is First Lieutenant (10000 - 20000 Reputation Level)paulh1983 User rank is First Lieutenant (10000 - 20000 Reputation Level)paulh1983 User rank is First Lieutenant (10000 - 20000 Reputation Level)paulh1983 User rank is First Lieutenant (10000 - 20000 Reputation Level)paulh1983 User rank is First Lieutenant (10000 - 20000 Reputation Level)paulh1983 User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 2 Weeks 1 Day 21 h 54 m 4 sec
Reputation Power: 201
you just need another if statement to check whether name was empty or not and if empty do an alert.

if (something == "" ) {
alert..
}

Reply With Quote
  #3  
Old March 19th, 2013, 08:42 AM
chrisjchrisj chrisjchrisj is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 44 chrisjchrisj User rank is Sergeant (500 - 2000 Reputation Level)chrisjchrisj User rank is Sergeant (500 - 2000 Reputation Level)chrisjchrisj User rank is Sergeant (500 - 2000 Reputation Level)chrisjchrisj User rank is Sergeant (500 - 2000 Reputation Level)chrisjchrisj User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 5 h 29 m 56 sec
Reputation Power: 15
thanks, but...

I tried this without success, any other help will be appreciated:

<script type="text/javascript">
function checkemail(){
var str=document.myform.email_address.value;
var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
if (filter.test(str))
testresults=true;
else {
alert("Please input a valid email address!");
return false;
}
if(document.myform.agree.checked!=1) {
alert("Please check the box to agree to the Terms.");
return false;
}
if(document.myform.contact_name.value!=0) {
alert("Please enter your full name.");
return false;
}
if(document.myform.ans.value.toLowerCase()!="white") {
alert("Please answer security question correctly: Black or White?");
return false;
}
return true;
}
</script>

Reply With Quote
  #4  
Old March 19th, 2013, 10:37 AM
Edge360 Edge360 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2013
Posts: 36 Edge360 User rank is Sergeant Major (2000 - 5000 Reputation Level)Edge360 User rank is Sergeant Major (2000 - 5000 Reputation Level)Edge360 User rank is Sergeant Major (2000 - 5000 Reputation Level)Edge360 User rank is Sergeant Major (2000 - 5000 Reputation Level)Edge360 User rank is Sergeant Major (2000 - 5000 Reputation Level)Edge360 User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Day 14 h 7 m 51 sec
Reputation Power: 22
Try...

Code:
<script type="text/javascript">
	function checkemail(){
		var str=document.myform.email_address.value;
		var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
		if (filter.test(str))
			testresults=true;
		else {
			alert("Please input a valid email address!");
			return false;
		}
		if(document.myform.agree.checked!=1) {
			alert("Please check the box to agree to the Terms.");
			return false;
		}
		if(document.myform.contact_name.value == "") {
			alert("Please enter your full name.");
			return false;
		}
		if(document.myform.ans.value.toLowerCase()!="white") {
			alert("Please answer security question correctly: Black or White?");
			return false;
		}
		return true;
	}
</script>

Reply With Quote
  #5  
Old March 19th, 2013, 10:55 AM
chrisjchrisj chrisjchrisj is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 44 chrisjchrisj User rank is Sergeant (500 - 2000 Reputation Level)chrisjchrisj User rank is Sergeant (500 - 2000 Reputation Level)chrisjchrisj User rank is Sergeant (500 - 2000 Reputation Level)chrisjchrisj User rank is Sergeant (500 - 2000 Reputation Level)chrisjchrisj User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 5 h 29 m 56 sec
Reputation Power: 15
Thanks

Thanks alot for the help

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > Making Contact_Name a mandatory Form field

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap