Client Script on Modal not alerting

Aaron Duncan
Mega Sage

I have a function in a modal where if the choicelist is Other(value 3) it checks to make sure the text area below has text entered. If the text area has something, I need it to return true and continue back in the previous function.

 

Right now, if nothing is selected in the choicelist, the alert pops correctly, but if the choiclist is Other and the text field is blank, it does NOT fire the alert.  This is the function in the Client Script portion of the UI Page. 

 

function validateComments() {
	var earlyReason = gel('EarlyReason').value;
    var earlyText = gel('otherComment').value;

    //Make sure dialog comments are not empty
    if (earlyReason == "") {
        //If comments are empty stop submission
        alert("Select the early change reason before continuing.");
        return false;
    }
    else if ((earlyReason == 3) && (earlyText == '' || earlyText == null)) {
			alert("You must provide detail why you are releasing early.");
			return false;
		}
	else {
		return true;
	}
    }

 

2 REPLIES 2

Gangadhar Ravi
Giga Sage
Giga Sage

check typeof for earlyReason if that is coming as string try 

else if ((earlyReason == '3') && (earlyText == '' || earlyText == null)) 

I checked and it is coming back as a string. What's interesting is that I tested the length on an empty value and it comes back as comment.length == 1. I'm not sure why that is, but your typeof helped point the way.