Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 2013-10-28
6
348 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Coldusion - DATA insert syntax problem 12 49
Multiflying 2 Input Text On a Table 7 31
jQuery Scroll To Top 5 38
ASP.NET Content Page 3 25
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

839 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