[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

how do you write an if this or this then statement in Jquery

Posted on 2014-08-06
7
Medium Priority
?
259 Views
Last Modified: 2014-08-06
Hi I am trying to write a if then statement with Jquery... to no avail..

I have a hidden input (named recipientId)  that gets a value based on an <a id>  

what I want is to show a  form if the value of recipientId is 6,5,4...

This is what I have so far..

Thanks for help!!!

<script>
$(document).ready(function() { 
 var v = $(this).attr("id");
        $("#recipientId").val(v);
	if 	($("#recipientId").val("6"), $("#recipientId").val("5"), $("#recipientId").val("4")) {

//show div
		
		
	}
})
</script>

Open in new window

0
Comment
Question by:smfmetro10
  • 4
  • 3
7 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 40244511
<script>
$(document).ready(function() { 
	var v = $(this).attr("id");
	if($("#recipientId").val()==6 || $("#recipientId").val()==5 || $("#recipientId").val()==4) {
		//show div
	}
})
</script>

Open in new window

0
 

Author Comment

by:smfmetro10
ID: 40244616
For some reason I can't get the form to show...

I tried using to trigger an alert but can't seem to get that to fire as well

<script>
$(document).ready(function() { 
	var v = $(this).attr("id");
	if($("#recipientId").val()==6 || $("#recipientId").val()==5 || $("#recipientId").val()==4) {
	alert("It works!");
	}
})
</script>

Open in new window

0
 
LVL 58

Expert Comment

by:Gary
ID: 40244618
Link to the page?
Are you including the jQuery library before that code?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 58

Expert Comment

by:Gary
ID: 40244756
What is this
$(this).attr("id");

supposed to be referencing?
0
 
LVL 58

Accepted Solution

by:
Gary earned 2000 total points
ID: 40244790
Actually the code doesn't make sense at all.
I'm guessing this code

	if($("#recipientId").val()==6 || $("#recipientId").val()==5 || $("#recipientId").val()==4) {
	alert("It works!");
	}

Open in new window

should be inside your onclick function earlier in the page.
0
 

Author Closing Comment

by:smfmetro10
ID: 40244842
Ah! Thanks!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…
Suggested Courses
Course of the Month20 days, 13 hours left to enroll

864 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