emi_sastra
asked on
Missing getElementsByTagName.
Hi,
My code are below in aspx:
<script type="text/javascript">
{
var control = document.getElementById("t extbox1");
}
</script>
My questionis why I can not get "getElementsByTagName" property when I code document?
It just have "getElementById" and "getElementByName" Property.
Thank you.
My code are below in aspx:
<script type="text/javascript">
{
var control = document.getElementById("t
}
</script>
My questionis why I can not get "getElementsByTagName" property when I code document?
It just have "getElementById" and "getElementByName" Property.
Thank you.
What are you basically looking for?
ASKER
Hi Asvforce,
Why I just have two properties 'getElementById" and "getElementByName"?
In this case I can not use document.getElementsByTagN ame.
Thank you.
Why I just have two properties 'getElementById" and "getElementByName"?
In this case I can not use document.getElementsByTagN
Thank you.
you can still use getElementsByTagName , even its not showing up
see sample
<input type="text" name="t1" id="t2">some text</input>
for this you can either use this
document.getElementById("t 2").value
or
document.getElementByName( "t1").valu e
Note: It all depends on what property you have in your html tag, normally you will see name property so just use getElementByName
<input type="text" name="t1" id="t2">some text</input>
for this you can either use this
document.getElementById("t
or
document.getElementByName(
Note: It all depends on what property you have in your html tag, normally you will see name property so just use getElementByName
ASKER
Here are my more code:
<script type="text/javascript" >
function Set_Control()
{
var control = document.getElementsByTagN ame("asp:T extBox");
alert( control.length)
for ( var i = 0; i < control.length; i++) {
alert('Hello')
}
}
</script>
<body onload="Set_Control()">
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextB ox>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextB ox>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</div>
</form>
</body>
It just show 0.
Thank you.
<script type="text/javascript" >
function Set_Control()
{
var control = document.getElementsByTagN
alert( control.length)
for ( var i = 0; i < control.length; i++) {
alert('Hello')
}
}
</script>
<body onload="Set_Control()">
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextB
<asp:TextBox ID="TextBox2" runat="server"></asp:TextB
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</div>
</form>
</body>
It just show 0.
Thank you.
Put the script inside for tag
<body onload="Set_Control()">
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</div>
<script type="text/javascript" >
function Set_Control()
{
var control = document.getElementsByTagName("asp:TextBox");
alert( control.length)
for ( var i = 0; i < control.length; i++) {
alert('Hello')
}
}
</script>
</form>
</body>
Actually I think its working for HTML tags only
So you want to find all text box controls? If yes then use this
<script type="text/javascript" >
function Set_Control()
{
var control = document.getElementsByTagN ame("input ");
alert( control.length);
for ( var i = 0; i < control.length; i++) {
if(control[i].type == "text")
alert('Hello' + control.name);
}
}
</script>
<script type="text/javascript" >
function Set_Control()
{
var control = document.getElementsByTagN
alert( control.length);
for ( var i = 0; i < control.length; i++) {
if(control[i].type == "text")
alert('Hello' + control.name);
}
}
</script>
ASKER
Hi asvforce,
It shows nothing. Since there is no "input" tag there.
Thank you.
It shows nothing. Since there is no "input" tag there.
Thank you.
It will show you input tag when the html file is created, not while coding. So the <asp:TextBox will change to input tag like <input type="text". So just view the source code of you HTML file which is being shown and you will see <input type="TEXT" something instead of <asp:TextBox. Also try using this script
function Set_Control()
{
var control = document.getElementsByTagN ame("input ");
alert( control.length);
for ( var i = 0; i < control.length; i++) {
if(control[i].type.toLower Case() == "text")
alert('Hello' + control.name);
}
}
</script>
function Set_Control()
{
var control = document.getElementsByTagN
alert( control.length);
for ( var i = 0; i < control.length; i++) {
if(control[i].type.toLower
alert('Hello' + control.name);
}
}
</script>
ASKER
Hi asvforce,
This time it show 6 and "Helloendefine"
Thank you.
This time it show 6 and "Helloendefine"
Thank you.
Good, so now you are good. see the script where i have written Hello' + control.name so endefine is the name, and in all total there are 6 text boxes on your html page. I guess from here you have to carry forward with what you want to do. Or else let me know what exactly you want to do and /or looking to do.
Sorry there are 6 <input tags and the Helloendefine is the name which i was trying to display so better use this to view what text boxes are comming
function Set_Control()
{
var control = document.getElementsByTagN ame("input ");
alert( control.length);
for ( var i = 0; i < control.length; i++) {
if(control[i].type.toLower Case() == "text")
alert('Hello: ' + control.id);
}
}
function Set_Control()
{
var control = document.getElementsByTagN
alert( control.length);
for ( var i = 0; i < control.length; i++) {
if(control[i].type.toLower
alert('Hello: ' + control.id);
}
}
ASKER
Hi asvforce,
Still show 6 and "Hello : undefined"
Thank you.
Still show 6 and "Hello : undefined"
Thank you.
Do one thing, when you see the html file or the web page, please copy the source and paste it here.
ASKER
Hi asvforce,
Still show 6 and "Hello : undefined"
This code alert('Hello: ' + control.id); should be changed to:alert('Hello: ' + control[i].id)
And it works.
Thank you.
Still show 6 and "Hello : undefined"
This code alert('Hello: ' + control.id); should be changed to:alert('Hello: ' + control[i].id)
And it works.
Thank you.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yes, my problem is solved.
Thank you very much.
Thank you very much.
var control = document.getElementById("i
as its TAG name like <input