• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 359
  • Last Modified:

how do you make an email field required into my script.

I have a script which is working fine for question 1.  I would like to make the 'email' field mandatory.  How can you add this to my script.? Some time that field contains automated data from the database, sometime user has to enter his email.  So in case the email field is empty, I would like to ask user 'please add your email'.  how can you add this to my existant javascript.


Here is my code:
E-Mail: <cfoutput><input type="text" name="email" value="#DisplayEmail.email#" size="50"></cfoutput>

<p><label for="strEmail"><strong><strong>1.</strong> If your skill set? </label>
<cfoutput><input type="radio" name="contactme" id="contactme" value="Yes">Yes &nbsp;
<input type="radio" name="contactme" id="contactme" value="No">No</cfoutput>

Here is my JavaScript:


<script type="text/javascript">
// checks buttons (radio, checkbox) - coursesweb.net
function checkButons(frm) {
var re = false;           // used to determine when a button is checked
var ree = false;
var err = '';             // to store the errors

//var question1 = document.getElementById('contactme').checked;          // contains an array with all radio buttons "vegetable"
//alert(question1);
// create an Array in JSonn format with checkbox buttons
//var question2 = [frm.CMTEE_PREF_NEW];
// traverse the radio buttons
// if one is checked sets re to true, and stops the iteration with "break"
for(var i=0; i<frm.contactme.length; i++) {
  if(frm.contactme[i].checked) {
    re = true;
    break;
  }
}
// if "re" is false means no radio button checked, add error in "err" 
if(re == false) err += '- Question 1: Please select « yes » or « no ».';

for(var i=0; i<frm.CIAPermissionProfile.length; i++) {
  if(frm.CIAPermissionProfile[i].checked) {
    ree = true;
    break;
  }
}


// make "re" again False, and traverse the checkbox buttons
// if one is checked sets re to true, and stops the iteration with "break"
re = false
for(var i=0; i<frm.CMTEE_PREF_NEW.length; i++) {
  if(frm.CMTEE_PREF_NEW[i].checked) {
    re = true;
    break;
  }
}

// if "re" is false means no checkbox button checked, add error in "err" 
if (re == false) err += '\n- Question 2: You must check at least one types of committee.';

// if "re" is false means no radio button checked, add error in "err" 
if(ree == false) err += '\n- Question 11: Please select « yes » or « no ». Please try again.';

// if "err" not empty, alert the error(s) and returns False to stop submitting form
if(err != "") {
  alert(err);
  return false;
}
else return re;
}




--></script>

Open in new window

0
koila
Asked:
koila
  • 2
  • 2
2 Solutions
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
just add the following to your main validation script:

    if( document.getElementById('email').value == '' )
         alert( 'Please fill out your email.' );

Open in new window

0
 
RobOwner (Aidellio)Commented:
I've requested that this question be deleted for the following reason:

The question has either no comments or not enough useful information to be called an "answer".
0
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
I believe the code I provided does exactly what the OP is asking, it should be up to the OP to confirm that it did or did not work.
0
 
RobOwner (Aidellio)Commented:
@The_Big_Daddy,

I checked you're code before closing.  There is no ID "email" in the OP's code and hence your code wouldn't work:

E-Mail: <cfoutput><input type="text" name="email" value="#DisplayEmail.email#" size="50"></cfoutput>

The correct output would be to state that the ID needs to be added or another way of obtaining the element be shown.

Given what I've said, feel free to add anything further and I'll review.

tagit
Topic Advisor
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now