Solved

IF/AND Javascript Issues

Posted on 2014-02-07
13
235 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
  • 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
 

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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SharePoint 2013 Blog Template 2 36
Polygon I google maps 1 16
Show/Hide ASP.NET controls with JQuery best practices 3 18
how can i count words? 2 18
Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
The viewer will learn how to dynamically set the form action using jQuery.
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…

920 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now