Solved

IF/AND Javascript Issues

Posted on 2014-02-07
13
225 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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
The viewer will learn how to dynamically set the form action using jQuery.
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)

707 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

12 Experts available now in Live!

Get 1:1 Help Now