Mare22
asked on
javascript / jquery selector for getting control's attribute
I am running Visual Studio 2010. The problem is I don't know how to get the value of a control's' custom attribute.
Here is my HTML:
<div class="row">
<asp:RadioButton runat="server" class="petsRadioButton" ID="rbLiveStock" Text=" Livestock - Please Describe: " breedCd="LIVESTOCK" />
<asp:TextBox runat="server" ID="txtLivestockDesc" onchange="txtLivestockDesc _Updated(t his.value) " style="width:100px; margin-top: 2px;" />
</div>
I am trying to get the value of breedCd attribute of the radio button above.
Here is the relevant cut from the page generated by VS:
<div class="row">
<span class="petsRadioButton" breedCd="LIVESTOCK"><input id="ctl00_Main_rbLiveStock " type="radio" name="ctl00$Main$rbLiveSto ck" value="rbLiveStock" /><label for="ctl00_Main_rbLiveStoc k"> Livestock - Please Describe: </label></span>
<input name="ctl00$Main$txtLivest ockDesc" type="text" id="ctl00_Main_txtLivestoc kDesc" onchange="txtLivestockDesc _Updated(t his.value) " style="width:100px; margin-top: 2px;" />
</div>
Here is my function:
function txtLivestockDesc_Updated(t ext) {
debugger
var radioButtonChecked = false;
var rbLiveStock = 'ctl00_Main_rbLiveStock';
if (text != null && text.trim() != "") {
$(rbLiveStock).attr('check ed', 'checked');
radioButtonChecked = true;
}
else {
$(rbLiveStock).attr('check ed') ? radioButtonChecked = true : radioButtonChecked = false;
}
var breedCd1 = $(rbLiveStock).parent().at tr('breedC d'); //undefined
//var breedCd2 = rbLiveStock.parent.getAttr ibute('bre edCd'); // parent is null or not an object
var breedCd3 = $(rbLiveStock.parent).attr ('breedCd' ); // undefined
updateAnimalExposureInfo($ (rbLiveSto ck.parent) .attr('bre edCd'), radioButtonChecked, text);
}
Please help me get the value of the breedCd attribute.
Thank you.
in the txtLivestockDesc_Updated function:
function txtLivestockDesc_Updated(t ext) {
debugger
var radioButtonChecked = false;
var rbLiveStock = '<%=rbLiveStock.ClientID%> ';
if (text != null && text.trim() != "") {
$(rbLiveStock).attr('check ed', 'checked');
radioButtonChecked = true;
}
else {
$(rbLiveStock).attr('check ed') ? radioButtonChecked = true : radioButtonChecked = false;
}
var breedCd = $(rbLiveStock.parent).attr ('breedCd' );
}
Here is my HTML:
<div class="row">
<asp:RadioButton runat="server" class="petsRadioButton" ID="rbLiveStock" Text=" Livestock - Please Describe: " breedCd="LIVESTOCK" />
<asp:TextBox runat="server" ID="txtLivestockDesc" onchange="txtLivestockDesc
</div>
I am trying to get the value of breedCd attribute of the radio button above.
Here is the relevant cut from the page generated by VS:
<div class="row">
<span class="petsRadioButton" breedCd="LIVESTOCK"><input
<input name="ctl00$Main$txtLivest
</div>
Here is my function:
function txtLivestockDesc_Updated(t
debugger
var radioButtonChecked = false;
var rbLiveStock = 'ctl00_Main_rbLiveStock';
if (text != null && text.trim() != "") {
$(rbLiveStock).attr('check
radioButtonChecked = true;
}
else {
$(rbLiveStock).attr('check
}
var breedCd1 = $(rbLiveStock).parent().at
//var breedCd2 = rbLiveStock.parent.getAttr
var breedCd3 = $(rbLiveStock.parent).attr
updateAnimalExposureInfo($
}
Please help me get the value of the breedCd attribute.
Thank you.
in the txtLivestockDesc_Updated function:
function txtLivestockDesc_Updated(t
debugger
var radioButtonChecked = false;
var rbLiveStock = '<%=rbLiveStock.ClientID%>
if (text != null && text.trim() != "") {
$(rbLiveStock).attr('check
radioButtonChecked = true;
}
else {
$(rbLiveStock).attr('check
}
var breedCd = $(rbLiveStock.parent).attr
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Check this : http://jsfiddle.net/mSV4T/
var rbLiveStock = '#<%=rbLiveStock.ClientID% >';
var rbLiveStock = '#<%=rbLiveStock.ClientID%
function txtLivestockDesc_Updated(text) {
var radioButtonChecked = false;
var rbLiveStock = '#<%=rbLiveStock.ClientID%>';
if (text != null && text.trim() != "") {
$(rbLiveStock).attr('checked', true);
radioButtonChecked = true;
}
else {
$(rbLiveStock).is(':checked') ? (radioButtonChecked = true) : (radioButtonChecked = false);
}
var breedCd = $(rbLiveStock).parent().attr('breedCd');
}
ASKER