Show element based on value of number...

User 2343114 Photo


Registered User
5 posts

How can I write a rule to show an element based on the value of a number element.
For instance if the value is 2 then name2 element displays.
Thanks
Keith
User 187934 Photo


Senior Advisor
20,271 posts

Hi Keith,
Try this.
Adjust the number1,item3 and the text1 to your form needs.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js">
</script>
<script>
// version 1
var jQ = $.noConflict(true);
jQ( document ).ready(function() {
jQ("#docContainer #item3").css("display", "none");
jQ("input[name='number1']").change(function() {
if(jQ(this).val() == 2){
jQ("#docContainer #item3").css("display", "block");
jQ("input[name='text1']").val("You entered 2");
}else{jQ("#docContainer #item3").css("display", "none");}
});

});</script>

I can't hear what I'm looking at.
It's easy to overlook something you're not looking for.

This is a site I built for my work.(RSD)
http://esmansgreenhouse.com
This is a site I built for use in my job.(HTML Editor)
https://pestlogbook.com
This is my personal site used for testing and as an easy way to share photos.(RLM imported to RSD)
https://ericrohloff.com

Have something to add? We’d love to hear it!
You must have an account to participate. Please Sign In Here, then join the conversation.