Chris wrote:
Hi,
I have been trying for an hour now with this. I need to pass the value from
one textbox1 to textbox2, when a button is clicked, using javascript.
textbox2 is within a panel.
This is the script
<script type="text/javascript">
function onOk()
{
var x = document.all.Textbox2.Value;
//var x = document.getElementById("Textbox2").Value;
//document.getElementById('<%= Textbox2.Text %>').innerText;
document.getElementById("Textbox1").value=x;
}
</script>
Please advice.
Thanks
Hey Chris,
Try using "document.getElementById('<%= Textbox1.ClientID %>')" to get
the element. Another route would be to browse to the page, view the
rendered html, and get the id from there. ClientID will be more
flexible should your page change.
Below is my go at it. You didn't include the markup for the textboxes
or the panel, so I can't be sure this will work.
function onOk()
{
var textbox1 = document.getElementById('<%= Textbox1.ClientID %>');
var textbox2 = document.getElementById('<%= Textbox2.ClientID %>');
textbox1.value = textbox2.value;
}
Note that document.all is an Internet Explorer only feature and
document.getElementById is the recommended way. innerText is also ie
only. value should be lower case. Some browsers ignore case, but
others don't.
--
David Hogue