Webmaster Forum

Go Back   Webmaster Forum > Web Development > Coding Forum

Coding Forum Problems with your code? Discuss coding issues, including JavaScript, PHP & MySQL, HTML & CSS, Flash & ActionScript, and more.


Closed Thread
 
Thread Tools Display Modes
Share |
  #1  
Old 03-18-2013, 07:23 AM
chrisjchrisj chrisjchrisj is offline
Contributing Member
 
Join Date: 04-05-10
Posts: 77
iTrader: 0 / 0%
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>
 

Advertisement

Advertisement

  #2  
Old 03-18-2013, 02:45 PM
smanaher's Avatar
smanaher smanaher is offline
v7n Mentor
 
Join Date: 03-04-13
Location: Oneonta, NY
Posts: 329
iTrader: 0 / 0%
Chrisjchrisj,

You could just insert this code into your form,
PHP Code:
if(document.forms.contact.fullName.value!=0)
{
alert("Please enter your full name.");
return 
false;

Of course this will just through an alert when the box is empty.

Hope that helps,

Shawn

Last edited by snakeair; 03-20-2013 at 10:11 PM. Reason: add code tags
 
  #3  
Old 03-18-2013, 07:11 PM
chrisjchrisj chrisjchrisj is offline
Contributing Member
 
Join Date: 04-05-10
Posts: 77
iTrader: 0 / 0%
thanks

Thanks. you are very kind tp ost a suggestion, however it didn't work in the way I added it, as shown below. Any additional help will be appreciated.

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.forms.contact.fullName.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>

No alert appear when the contact_name field was empty.

I also tried:




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!=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>
 
  #4  
Old 03-20-2013, 11:29 AM
smanaher's Avatar
smanaher smanaher is offline
v7n Mentor
 
Join Date: 03-04-13
Location: Oneonta, NY
Posts: 329
iTrader: 0 / 0%
Chris,

Sorry I should have been more clear.

Are you certain that your HTML is configured correctly? So for example in the Javascript statement you have, you are referencing an input field with the name “contact_form”.

Your input should look something like this
<input name=”contact_form” />

Is that the way you have it set up?
 
Go Back   Webmaster Forum > Web Development > Coding Forum

Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Form Field with 2checkout Sears Buy Web Services 1 01-24-2012 04:59 PM
Form field that loads a sub field sstoney200 Coding Forum 22 01-24-2012 07:16 AM
Form field security issues nullwired Coding Forum 7 07-01-2009 01:19 PM
Dynamic Form Field Bushstar Web Design Lobby 2 03-24-2009 07:00 PM
jump to form field younghistorians Coding Forum 3 06-04-2004 07:45 AM


V7N Network
Get exposure! V7N I Love Photography V7N SEO Blog V7N Directory


All times are GMT -7. The time now is 07:44 AM.
Powered by vBulletin
Copyright 2000-2014 Jelsoft Enterprises Limited.
Copyright © 2003 - 2018 VIX-WomensForum LLC