Solved

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

Posted on 2013-10-28
6
349 Views
Last Modified: 2013-12-18
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
Comment
Question by:koila
  • 2
  • 2
6 Comments
 
LVL 33

Accepted Solution

by:
Big Monty earned 250 total points
ID: 39606284
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
 
LVL 43

Expert Comment

by:Rob
ID: 39674874
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
 
LVL 33

Expert Comment

by:Big Monty
ID: 39674875
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
 
LVL 43

Assisted Solution

by:Rob
Rob earned 250 total points
ID: 39708151
@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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ASP sending two datas 2 23
arrays and radio buttons 10 40
what should i learn? javascript or typescript? 3 40
Table doesn't show the lines! 3 25
Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question