Monday, March 26, 2012

Change asp:ListItem Asynchronously

Hi. I′m trying to change the asp:ListItemText value asynchronously from asp:Textbox value.

The html-output from asp:RadioButtonList is somthing like this (simplefied version) :

<table id="x" border="0">
<tr>
<td><input id="x_0" type="radio" name="x" value="Value 0" /><label for="x_0">Text 0</label></td>
<td><input id="x_1" type="radio" name="x" value="Value 1" /><label for="x_1">Text 1</label></td>
<td><input id="x_2" type="radio" name="x" value="Value 2" /><label for="x_2">Text 2</label></td>
</tr>
</table>

As you can see, there is no id for the following "label".

I can change the input value: $get("x_0").value = "something";

But how can I change the following label .innerHtml. That is f.x. the "Text 0" string ?

I believe the following should work:

$get("x_0").innerHTML = "something";

------------------
When you ask a question, remember to click "mark as answered" when you get a reply which answers your question.


Thanks, but that is not the solution, because the input is closed before the label starts.

If this was the case... :
<input id="x_0" type="radio" name="x" value="Value 0"><label for="x_0">Text 0</label></input>

...in stead of how it is:
<input id="x_0" type="radio" name="x" value="Value 0" /><label for="x_0">Text 0</label>

Then I would not have a problem.


Since there is no ID for the label, you have to loop through the labels of the list to find the one that matches the radio button id you are looking for

var container = document.getElementByID("x");

var labels = container.getElementsByTagName("LABEL");

for(var x = 0; x < labels.length; x++)
{
if(labels[x].htmlFor == "x_0")
labels[x].innerText = "changed 0";
}


Thank you DMAR78. This works great.Party!!!

No comments:

Post a Comment