Reputation: 7618
I need to edit a div content based on a user choice with a radio button interface.
This is my html:
<input type="radio" name="account_type" id="account_name_type" checked="checked" value="username">
<label for="account_name_type" id="account_name_label" class="custom_font">{{ user:username }}</label>
<input type="radio" name="account_type" value="nome_cognome">
<div class="cont_input">
<input id="nome" name="nome" type="text" value="{{ user:first_name }}">
</div>
<div class="cont_input">
<input id="cognome" name="cognome" type="text" value="{{ user:last_name }}">
</div>
And this is the script:
$("input[name='account_type']").change(function() {
var selezionato = $("input[name='account_type']:checked").val();
if( $.trim(selezionato) == "nome_congome" )
{
//var nome = $('#nome').attr('value');
//var cognome = $('#cognome').val();
//$('#mittente_step2').html(nome+' '+cognome);
alert('nome_cognome');
}
else
{
//var user = $('#account_name_label').text();
//$('#mittente_step2').html(user);
alert('user');
}
});
});
All I need to do right now is alert
the type of choice but everytime it goes to the else
code.
Why my if
doen't work?
Upvotes: 1
Views: 62
Reputation: 354
if($("input[name='account_type']").is(':checked');){
alert('nome_cognome');
}else{
}
Upvotes: 0
Reputation: 35223
Try this
var selezionato = $(this).val(); // or this.value
assuming you want to point to the radio button currently being changed.
Upvotes: 0
Reputation: 15112
You have a typo
nome_cognome != nome_congome
if( $.trim(selezionato) == "nome_cognome" )
^ Here
Upvotes: 1