IF/AND Javascript Issues

Why doesn't this:

$('#frmOneSearch').on("click",function(e){
    if ( ($('#frmseclev').val() != "") && ($('#frmrole').val() != "" ) && ($('#searchstring').val() != "") ) {
	  
window.location.assign('index.cfm?do=admin:email&emailstep=recipients&searchString=' + $('#searchString').val() );
	
} else {
         return alert('A search term is required.');
     }
 });

Open in new window


check to see if frmseclev AND frmrole AND searchstring ARE ALL not blank? It seems like it's checking if any one of them is not blank. Any idea?
traportAsked:
Who is Participating?
 
GaryCommented:
Try this

if ( $('#frmseclev:selected').val() != "" && $('#frmrole:selected').val() != ""  && $('#searchstring').val() != "")  {

If that doesn't work then just alert the values and see what you get.
0
 
GaryCommented:
What are your three input elements.
0
 
traportAuthor Commented:
name= frmseclev (type:select)
name= frmrole (type:select)
name= searchstring (type:input)
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
GaryCommented:
I meant the HTML
0
 
traportAuthor Commented:
Oh, sorry...

<form name="frmOne" id="frmOne" method="get" action="email?emailstep=recipients">
		<div class="row-fluid">
    	<div class="span2 text-right">
    		<label for=""><strong>Organization</strong></label>
        </div>
    	<div class="span2">
      		<select multiple="multiple" name="frmseclev" id="frmseclev" size="8" style="min-width:200px; width:200px;">
            	<option value="" selected>Please Select</option>
				<cfoutput query="qTiers">
				<option value = "#qTiers.TierID#">#qTiers.TreeTierLabel#</option>
				</cfoutput>
			</select>
    	</div>
        <div class="span2 text-right">
        	<label for =""><strong>Role</strong></label>
        </div>
        <div id="selectRoleBlock" class="span2">
			<select name="frmrole" id="frmrole" size="8" multiple style="min-width:200px; width:200px;">
            	<option value="" selected>Please Select</option>
				<cfoutput query="qRoles">
				<option value="#qRoles.seclev#">#qRoles.role#</option>
				</cfoutput>
			</select>
  		</div> 
	</div>  
    <br>
<cfoutput>
	<div class="row-fluid text-right">
	<div class="control-group span7">
		<label class="control-label" for="searchString">Search:</label>
		<div class="controls">
		<input type="text" id="searchString" name="searchString" class="input-medium" value="#rc.searchString#" />
		</div>
	
		<input type="button" class="button extrapadding" id="frmOneSearch" value="Search" />
		<input type="button" class="button extrapadding" id="frmOneClear" value="Clear" />
  	</div>
    </div>
</form>

Open in new window

0
 
traportAuthor Commented:
I'm in CFML and I can't figure out how to output my variables in js (on a js page).

alert('<cfoutput>#variablename#</cfoutput>');

doesn't work.

Thanks. Going to try now. Appreciate your help.
0
 
GaryCommented:
Just add before your check

alert( $('#frmseclev:selected').val() )
alert($('#frmrole:selected').val())
alert($('#searchstring').val())
if ( $('#frmseclev:selected').val() != "" && $('#frmrole:selected').val() != ""  && $('#searchstring').val() != "")  {

Open in new window

0
 
traportAuthor Commented:
Well, very interesting...

Coming across as undefined...

??
0
 
GaryCommented:
alert( $('#frmseclev :selected').val() )
alert($('#frmrole :selected').val())
alert($('#searchstring').val())
if ( $('#frmseclev :selected').val() != "" && $('#frmrole :selected').val() != ""  && $('#searchstring').val() != "")  {

Open in new window

0
 
_agx_Commented:
(no points...)

Double check the code to ensure the case of of the javascript id's matches that of your form fields. For example "searchString" vs "searchstring".
0
 
GaryCommented:
Yes points for agx - I missed it.
0
 
traportAuthor Commented:
I missed it, too! Thanks so much to you both. Sorry it took me a bit to get back to you.
0
 
_agx_Commented:
Thanks guys!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.