jquery show/hide also need to show depending on returned database value

I’m using jquery to show/hide a form text input depending on the value of a checkbox:

$(document).ready(function(){

$(“input[name$=‘usr_type’]”).click(function(){
var radio_value = $(this).val();
if(radio_value==‘1’) {
$("#typeother").show(“slow”);
}
else if(radio_value==‘2’) {
$("#typeother").hide();
}
});
$("#typeother").hide();
});

Above works great.

However, I also need to SHOW the form input if a returned database value matches 1 as well.

[php]if ($gtprsn[‘usr_type’] == 1); { … how the freaking text input … }[/php]

Nothing I’ve tried so far works. I can add an if statement to the input itself to add a style and it will display:

[php]<?php if ($gtprsn['usr_type'] == 3): ?>style=“display:block !important;”<?php endif; ?>[/php]

But this then overrides the jquery and if I check the other radio button (value 2), the input still shows…

Suggestions?

I think I under stand the premiss but I do not have enough of the code to give you a coherent answer. If I understand the question your java works great when someone clicks a mouse on a specific check box the form is shown but the database results are not running through the PHP if/then properly. my question is what triggers the database query? and is your entire if them formatted correctly. In your post your second if/then is not its missing the {} portion. Could you post more of the code so we can troubleshoot further.

Sponsor our Newsletter | Privacy Policy | Terms of Service