pucko73
asked on
Find textbox inside formview in javascript
Can someone help me out how to find a textbox and set the value in JavaScript.
I get it to work on IE 11.0 but it fails on IE 8
var textbox = document.getElementById('< %=formView 1.FindCont rol("tbSom ething").C lientID %>');
var comments = textbox.value;
On IE8 textbox is null here.....
I get it to work on IE 11.0 but it fails on IE 8
var textbox = document.getElementById('<
var comments = textbox.value;
On IE8 textbox is null here.....
ASKER
the id is ct100_ContentPlaceHolder1_ formView1_ tbSomethin g
not found
empty dialog
not found
empty dialog
and on IE 11?
could you confirm when you see the first alert you can see the textbox in both cases?
could you confirm when you see the first alert you can see the textbox in both cases?
ASKER
I get the same result from both... It's just that I dont get an exception in the javacode for the script code on IE 11 it seems like.
On 11 i can se the textbox when I get the message with the id. (but i still get not found)
on 8 I can see the textbox when the dialog with the id is open.
On 11 i can se the textbox when I get the message with the id. (but i still get not found)
on 8 I can see the textbox when the dialog with the id is open.
ok, do a right to the page and choose view source on both.
try to locate the textbox and confirm the ID is the right one. Should not...
try to locate the textbox and confirm the ID is the right one. Should not...
ASKER
If i don't put this in the onoad function, just add the alert rows to my function that was called in a onclientclick of a button I get on 11:
id as above
not found
some text (ie the content of textbox... so I get the value here......
and on 8 I get an exception:
0x800a138f - JavaScript runtime error: Unable to get property 'value' of undefined or null reference....
id as above
not found
some text (ie the content of textbox... so I get the value here......
and on 8 I get an exception:
0x800a138f - JavaScript runtime error: Unable to get property 'value' of undefined or null reference....
Validate your page here : http://validator.w3.org/
ASKER
yes I can se the id ctl00_ContentPlaceHolder1_ formView1_ tbSomethin g in view source on both.
ASKER
Could it have something to do with it beeing a multiline textobox
I can se that view source show it as <textarea
I can se that view source show it as <textarea
the problem is when you try to read the data
you muts put the provided script alone in its own script tag (outside of any function) :
you muts put the provided script alone in its own script tag (outside of any function) :
<script>
window.onload = function() {
var id = '<%=formView1.FindControl("tbSomething").ClientID %>';
alert("the ID is :" + id); // for testing purpose
var textbox = document.getElementById(id);
alert("textbox " + (textbox==null)?"not found":"found" ); // for testing purpose
var comments = textbox.value;
alert(comments);
}
</script>
ASKER
Not much output from that.
Some warnings about:
The border attribute is obsolete. Consider specifying img { border: 0; } in CSS instead.
and
An img element must have an alt attribute, except under certain conditions. For details, consult guidance on providing text alternatives for images.
And:
The cellpadding attribute on the table element is obsolete. Use CSS instead.
Should not affect this.
Some warnings about:
The border attribute is obsolete. Consider specifying img { border: 0; } in CSS instead.
and
An img element must have an alt attribute, except under certain conditions. For details, consult guidance on providing text alternatives for images.
And:
The cellpadding attribute on the table element is obsolete. Use CSS instead.
Should not affect this.
great. hope you got my previous comment too.
ASKER
I'm not sure I understand what you mean with your previous comment?
The strange thing is when I debug it seems like the textbox is assigned and I can see the properties of it (running your onload function at least)
and it still say not found.....
The strange thing is when I debug it seems like the textbox is assigned and I can see the properties of it (running your onload function at least)
and it still say not found.....
any link to see your page?
ASKER
Unfortunately not. I don't have any public server to put on :(
What about this (wait 10s before the alerts) :
<script>
window.onload = function() {
setTimeout(function() {
var id = '<%=formView1.FindControl("tbSomething").ClientID %>';
alert("the ID is :" + id); // for testing purpose
var textbox = document.getElementById(id);
alert("textbox " + (textbox==null)?"not found":"found" ); // for testing purpose
var comments = textbox.value;
alert(comments);
},10000);
}
</script>
ASKER
still got the same.
id correct
not found
empty
id correct
not found
empty
ASKER
the not found thing is strange. because if there is something in the textbox
I get
id correct
not found
"content of textbox"
I get
id correct
not found
"content of textbox"
ASKER
So i guess that it works with your code in onload.... but when I have it in my code
it fails.
I call a function on a button OnClientClick
and that function calls anoter function that try to access the textbox
it fails.
I call a function on a button OnClientClick
and that function calls anoter function that try to access the textbox
ASKER
I also notice that on ie8 when I press my button the page don't show the TextBox after I pressed the button....
The first function that I calll shows a dialog where I can select some values... And whan I Close that dialog the function that try to read from textbox are called.
The first function that I calll shows a dialog where I can select some values... And whan I Close that dialog the function that try to read from textbox are called.
ASKER
I solved my problem by:
1. Change the function that I call in onClientClick on the button
to fetch the value from the combobox, then I pass that as a parameter to the second function I call.
So I guess that the problem is that the textbox in the page seems to disapear when I
show Another dialog from the javascript
1. Change the function that I call in onClientClick on the button
to fetch the value from the combobox, then I pass that as a parameter to the second function I call.
So I guess that the problem is that the textbox in the page seems to disapear when I
show Another dialog from the javascript
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I found the reason for the problem.
Seems like there is some bug with span tag in ie8.
In the dialog that I show I had:
if I changed that to
The page behind the dialog that I show did not "disaperar" and I can find the textbox etc.
i
Seems like there is some bug with span tag in ie8.
In the dialog that I show I had:
<b>Some Text: </b><span id="myid" />
if I changed that to
<b>Some Text: </b><span id="myid"> </span>
The page behind the dialog that I show did not "disaperar" and I can find the textbox etc.
i
ASKER
Thanks for all your help. I've learned a lot from you....
Open in new window