We help IT Professionals succeed at work.

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

smfmetro10
smfmetro10 asked
on
270 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

Comment
Watch Question

CERTIFIED EXPERT
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

CERTIFIED EXPERT
Expert of the Year 2014
Top Expert 2014

Commented:
Link to the page?
Are you including the jQuery library before that code?
CERTIFIED EXPERT
Expert of the Year 2014
Top Expert 2014

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

supposed to be referencing?
CERTIFIED EXPERT
Expert of the Year 2014
Top Expert 2014
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Ah! Thanks!
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.