[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2013-10-28
6
Medium Priority
?
352 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
[X]
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
  • 2
  • 2
6 Comments
 
LVL 33

Accepted Solution

by:
Big Monty earned 1000 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 1000 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

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

CFGRID Custom Functionality Series -  Part 1 Hi Guys, I was once asked how it is possible to to add a hyperlink in the cfgrid and open the window to show the data. Now this is quite simple, I have to use the EXT JS library for this and I achiev…
Hi. There are several upload tutorials using jquery and coldfusion. I found a very interesting one here Upload Your Files using Jquery & ColdFusion and Preview them (http://www.randhawaworld.com/) . I did keep the main js functions but made sever…
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…

649 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