Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Mar 2012
    Thanked 0 Times in 0 Posts

    editing stopWithAlert for checkbox status

    I am editing html/php/js code written by someone no longer with my organization. The item I am working with is a form. One of the form items is a checkbox that returns a value of "Yes" and posts that in the mysql db if checked. That is working. The .js script attached reviews the forms and returns a stopWithAlert value on required fields. It is working on previous values but I am trying to add one for the checkbox and I can't get it to work. It allows db submission if the checkbox is checked or not. I am a beginner at php and know very little about javascript.
    Here is the code for the form item:
    <p><strong><input type="checkbox" id="infocheck" name="infocheck" value="Yes" >I have reviewed all my entries above, and included all author and manuscript information as required.</strong></p>
    and here is the verify from script. The infocheck part is the one that is not working:
    function verifyForm() {
    	var requiredPeopleFields, pplErrs, a, b, c;
    	requiredPeopleFields = ["first_name", "last_name", "department", "institution", "address", "city", "country", "phone", "email"];
    	pplErrs = personObj.peopleErrors(requiredPeopleFields);
    	if (pplErrs) { return stopWithAlert("Please fill in this presenter's "+personObj.labelForField(pplErrs.name)+".", pplErrs); }
    	if (realForm.title.value == '') return stopWithAlert("Please enter the title of this manuscript.", realForm.title);
    	else if (realForm.keywords.value == '') return stopWithAlert("Please list a few keywords that apply to this manuscript.", realForm.keywords);
    	else if (realForm.manuscript.value == '') return stopWithAlert('Please attach your complete manuscript.', realForm.manuscript);
    	else if (realForm.blind.value == '') return stopWithAlert('Please attach your "blind" manuscript.', realForm.blind);
    	else if (realForm.infocheck.value == 'Yes') return stopWithAlert('Please review and approve your entry.', realForm.infocheck);
    	//Otherwise, looks good!
    	return true;
    Any help would be greatly appreciated.

  2. AdSlot6
  3. #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Sydney, Australia
    Thanked 726 Times in 715 Posts

    realForm.infocheck.value == 'Yes'


    realForm.infocheck.checked == true
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  4. Users who have thanked felgall for this post:

    learning curve (01-29-2013)

  5. #3
    New Coder
    Join Date
    Mar 2012
    Thanked 0 Times in 0 Posts
    Genius! That is it. Actually, I want to use false so the message shows up if they don't check the box. It seems really obvious now that I see it since I know the checkbox returns a true/false value, but it really had me stumped because I had the value of yes in my head as necessary to it. Thanks bunches!

  6. #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Thanked 4,945 Times in 4,906 Posts
    Quote Originally Posted by learning curve View Post
    It seems really obvious now that I see it since I know the checkbox returns a true/false value
    Not true. On the server side of things, the page that *receives* your <form> submission: A checkbox returns the value= of the checkbox if checked and *NOTHING AT ALL* if unchecked. If you don't assign a value= of your own, the browser supplies a default value (as I recall, it is "on") for you.

    No place does a checkbox "return" a true/false value.
    Be yourself. No one else is as qualified.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts