?
Solved

IF/AND Javascript Issues

Posted on 2014-02-07
13
Medium Priority
?
250 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
DFW AZURE MEETUP TONIGHT FRI 6PM

We will be discussing what Azure Stack is, how does it fit into the suit of offerings that Azure has currently, and where can it fit into your organizations technology stack. We will also be discussing limitations of the platform while covering various applicable scenarios.

 

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 1600 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 400 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

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…
Suggested Courses

777 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