SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Dec 2010
    Posts
    167
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Validate Radio Button

    When a select the radio button the error message isn't disappearing.

    Code JavaScript:
    function validate_accounttype(){
    		if (entrepreneur.checked !== "checked" && investor.checked !== "checked"){
    			show_error(accounttype_msg, 'Account type is required.');
    		}else{
    			removeChildren(accounttype_msg);
    			return true;
    		}
    	}

    Do I have the wrong syntax?

  2. #2
    SitePoint Addict bronze trophy AllanP's Avatar
    Join Date
    Sep 2010
    Location
    Australia
    Posts
    298
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    There are a couple of problems: entrepreneur.checked !== "checked" should be
    entrepreneur.checked == false; or, alternatively, entrepreneur.checked != true;

    Also, I wouldn't use !== as it means "not exactly equivalent in all respects", which means it will fail if you are comparing a string with a boolean, even though they may look alike.

  3. #3
    SitePoint Zealot
    Join Date
    Dec 2010
    Posts
    167
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by AllanP View Post
    There are a couple of problems: entrepreneur.checked !== "checked" should be
    entrepreneur.checked == false; or, alternatively, entrepreneur.checked != true;

    Also, I wouldn't use !== as it means "not exactly equivalent in all respects", which means it will fail if you are comparing a string with a boolean, even though they may look alike.
    Thank you... that fixed it.


Bookmarks

Posting Permissions

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