Hello and welcome to our community! Is this your first visit?
Register
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
    Posts
    18
    Thanks
    7
    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:
    Code:
    <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:
    Code:
    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
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,609
    Thanks
    0
    Thanked 645 Times in 635 Posts
    Replace:

    realForm.infocheck.value == 'Yes'

    with

    realForm.infocheck.checked == true
    Stephen
    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.

  • Users who have thanked felgall for this post:

    learning curve (01-29-2013)

  • #3
    New Coder
    Join Date
    Mar 2012
    Posts
    18
    Thanks
    7
    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!

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,133
    Thanks
    75
    Thanked 4,338 Times in 4,304 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.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

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