How to do this getElementsbyName for IE (and FF)?

This is JavaScript, with an error in IE, but it works in FF (the error is "document.getelementsbyname (...). 0.innerhtml is null or not an object":

var oldVal = parseInt(document.getElementsByName("outSL")[0].innerHTML); //val from DB

This is the asp.net code where I want to capture the internal html that will be populated by the database:

<asp:Label ID="LabelSL" runat="server" Text="" name="outSL" style="visibility:hidden;"></asp:Label>

The identifier is dynamic, when it is displayed, it looks like this: here I am 43:

<span id="ctl00_cpMainContent_LabelSL" name="outSL" style="visibility:hidden;">43</span>  

So ... how can I get this in IE and FF with the same function?

Thank!

0
source share
2 answers

.NET 4.0, , getElementById, Carnotaurus getElementByName .

http://weblogs.asp.net/scottgu/archive/2010/03/30/cleaner-html-markup-with-asp-net-4-web-forms-client-ids-vs-2010-and-net-4-0-series.aspx

.NET 2.0/3.5, jQuery .

http://api.jquery.com/category/selectors/

json- ID .NET 2.0/3.5.

http://awesomeclientid.codeplex.com/

http://www.philliphaydon.com/2010/12/i-love-clean-client-ids-especially-with-net-2-0/

INamingContainer, runat, :

<script type="text/javascript">
//<![CDATA[
var controls = {
"txtUserName": "ctl00_ContentPlaceHolder1_txtUserName",
"txtEmail": "ctl00_ContentPlaceHolder1_txtEmail",
"btnSubmit": "ctl00_ContentPlaceHolder1_btnSubmit"
};
//]]>
</script>

ID :

var element = document.getElementById(controls.btnSubmit);
+2

GetElementByName - . jQuery.

+6

All Articles