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

smfmetro10
smfmetro10 used Ask the Experts™
on
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

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Expert of the Year 2014
Top Expert 2014

Commented:
<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

Author

Commented:
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

Expert of the Year 2014
Top Expert 2014

Commented:
Link to the page?
Are you including the jQuery library before that code?
Exploring ASP.NET Core: Fundamentals

Learn to build web apps and services, IoT apps, and mobile backends by covering the fundamentals of ASP.NET Core and  exploring the core foundations for app libraries.

Expert of the Year 2014
Top Expert 2014

Commented:
What is this
$(this).attr("id");

supposed to be referencing?
Expert of the Year 2014
Top Expert 2014
Commented:
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.

Author

Commented:
Ah! Thanks!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial