0

Functionality:

Users need to submit in a form before being allowed to continue the functionality. The form consists of

Name:

Email:

Have Your Purchase: [ ]Yes [ ] No

[Submit]

Issue:

I have created the above form, enable the email validation function and have also enable the radio button to be a required field as well. However, this is the functionality at this point:

1.) When user doesn't input any field, a popup text will display: *please input all field

2.) When User input only name and not email, a popup text will display: * please input a valid email address

3.) In email field, when user doesn't input a correct email, a popup text will display: * please input a valid email address

However, at this point, after user has input both name and email, the page is navigated to the next page when the correct behaviour is that: *a popup text will display: please input all field for the user to select the option in the radio button.

I did not set the submit button as an tag, this is personal preference as i have set a function call Submit() to the button, hence, I am trying to find out what has gone wrong when I try to validate all fields.

Hence, what has gone wrong when Itry to validate all fields within the Submit function call method?

Please help.

code:

Luke
  • 982
  • 1
  • 7
  • 27

1 Answers1

1

Intead of

$.trim($("#Options").val()) == ""

Try this

$('#Options:checked').length == 0

Or

!$('#Options:checked').length

You condition should look like this

if( $.trim($("#NameField").val()) == "" || $.trim($("#EmailField").val()) == "" || !$('#Options:checked').length ) {
    console.log("email wrong");
    $("#email_wrong").html("* Please fill in all fields.");
    $("#email_wrong").fadeIn();
}
duduwe
  • 888
  • 7
  • 16