Reputation: 1
First attempt at using jQuery, but I'm pulling my hair out trying to get a basic functionality to work. I've got 2 radio buttons on a form, and depending on which one is selected, will update the value of an input text box in the same form. For the life of me I cannot get this to work! the same code will work if I choose to update an "h2" tag, or even the property of the text label next to the input text box. My jQuery code is as follows:
$(document).ready(function() {
$('input:radio[name=RGType]').click(function(){
var CompType = ($('input:radio[name=RGType]:checked').val());
//alert(CompType) // this works
$('#txt_Computername').text(CompType);
});
});
The area of HTML is as follows:
<tr>
<td style="text-align:right"><label for="RGType" id="t_Type">Computer Type:</label></td>
<td>
<label><input type="radio" name="RGType" value="SECDES" id="RGType_0">Desktop</label>
<label><input type="radio" name="RGType" value="SECLAP" id="RGType_1">Laptop</label>
</td>
</tr>
<tr>
<td style="text-align:right"><label for="txt_Computerame" id="t_Computername"><span class="required">* </span>Computer Name:</label></td>
<td><input id="txt_Computername" type="text" name="Computername" alt="Computer Name" style="width:60%" value="test" /></td>
</tr>
Using Firebug, it correctly identifies the current value in the text box as "test" - so I must be locating the correct element. If I change the text to be updated to #t_Computername (the adjecent label) it works!
What AM I missing???
thanks for any advice... sorry for dumb basic question!
Regards...
Upvotes: 0
Views: 75
Reputation: 66
You need to replace your
$('#txt_Computername').text(CompType);
with
$('#txt_Computername').val(CompType);
Upvotes: 0