1

I need to check to make sure that four fields have some kind of value in them. I have tried these ideas: Check whether a select box is empty How to tell if a DDL has options to select

My code is currently this:

    function goToConfirmStep() {
    var isAllowed = false;
    var type = $(".#tShowingType option:selected").val(); //DDL
    var startDate = $("#startDate").text(); //date picker
    var startTime = $("#startTime option:selected").val(); //DDL
    var endTime = $("showingLength option:selected").val(); //DDL
    if (type.val() ) { //&&   //(type != null || type != "")
    //(startDate.text() == "" || startDate.text() == null)) {//&&
    //($('#startTime').has('option').length > 0) &&
    //($('#endTime').has('option').length > 0)) {
    alert("here");

I left the comments in so you can tell what I have tried.

If they have values selected (which the 'type' and 'startTime' will have one selected on load), I want to move to the next page. I have an alert on the else to prevent them from moving forward if the fields aren't filled out.

4
  • i guess the .val() will give you the current value, in that case you can probably just check for type.val().length > 0 , which checks the length of the string Commented Jul 2, 2015 at 21:21
  • .val() never returns null, unless the selector doesn't match anything. Commented Jul 2, 2015 at 21:25
  • You don't need to use option:selected. The value of a dropdown is the value of the selected option. Commented Jul 2, 2015 at 21:25
  • so should I use .value() instead? Commented Jul 6, 2015 at 14:47

2 Answers 2

0

You should not use the && (and) operator because the alert gets displayed only if all the field are empty.

It should be something like:

function goToConfirmStep() {
    var isAllowed = false;
    var type = $(".#tShowingType option:selected").val(); //DDL
    var startDate = $("#startDate").text(); //date picker
    var startTime = $("#startTime option:selected").val(); //DDL
    var endTime = $("showingLength option:selected").val(); //DDL

    if (type == "" || startDate == "" || startTime == "" || endTime == "")
        alert("please fill in the required fields");
    else
        goToNextStep();
}
Sign up to request clarification or add additional context in comments.

Comments

0

I eventually had to attack it a different way. This is what I did:

Attacking this from a different angle.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.