javascript - Get Alt="" value from the selected radio button with jQuery -


i have following radio buttons within php loop:

<form>   <table class="table table-bordered optionschk">     <tr>       <td colspan="2"> select bench case </td>     </tr>     <?php foreach($db->getrecordset($sql) $bench){ ;?>     <tr>       <td class="w5">         <input type="radio" alt="<?php echo($bench['lbl']); ?>" value="<?php echo($bench['sno']); ?>" name="b_sno" id="b_<?php echo($bench['sno']); ?>">       </td>       <td class="w95"> <label for="b_<?php echo($bench['sno']); ?>"><?php echo($bench['lbl']); ?></label> </td>     </tr>     <?php       }     ?> 

i displaying values of above following function:

function donebenchselection() {   try {     var benchsno = $("input[type=radio][name=b_sno]:checked").val();     $("#benchsno").val(benchsno);     $("#obj_lst").html("selected bench label: "+$("input[type=radio][name=b_sno]:checked").text());   } catch(e) {     alert(e.message);   } } 

i want alt="some text" text selected radio button:

 $("#obj_lst").html("selected bench label: "+$("input[type=radio][name=b_sno]:checked").text()); 

is correct way? or not recommended way? please help.

to attribute value of element can use attr method or can use .prop method

try below code :

$('input[type="radio"]:checked').attr('alt'); 

Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -