Solved

IF/AND Javascript Issues

Posted on 2014-02-07
13
248 Views
Last Modified: 2014-02-08
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?
0
Comment
Question by:traport
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
  • 2
13 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 39842993
What are your three input elements.
0
 

Author Comment

by:traport
ID: 39843003
name= frmseclev (type:select)
name= frmrole (type:select)
name= searchstring (type:input)
0
 
LVL 58

Expert Comment

by:Gary
ID: 39843008
I meant the HTML
0
Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

 

Author Comment

by:traport
ID: 39843011
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
 
LVL 58

Accepted Solution

by:
Gary earned 400 total points
ID: 39843024
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
 

Author Comment

by:traport
ID: 39843033
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
 
LVL 58

Expert Comment

by:Gary
ID: 39843048
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
 

Author Comment

by:traport
ID: 39843055
Well, very interesting...

Coming across as undefined...

??
0
 
LVL 58

Expert Comment

by:Gary
ID: 39843069
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
 
LVL 52

Assisted Solution

by:_agx_
_agx_ earned 100 total points
ID: 39844081
(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
 
LVL 58

Expert Comment

by:Gary
ID: 39844117
Yes points for agx - I missed it.
0
 

Author Comment

by:traport
ID: 39844128
I missed it, too! Thanks so much to you both. Sorry it took me a bit to get back to you.
0
 
LVL 52

Expert Comment

by:_agx_
ID: 39844152
Thanks guys!
0

Featured Post

Tutorials alone can't teach real engineering

So we built better training tools.

-Hands-on Labs
-Instructor Mentoring
-Scenario-Based Tests
-Dedicated Cloud Servers

All at your fingertips. What are you waiting for?

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question