473,323 Members | 1,574 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

need help with javascript

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

Jun 15 '06 #1
6 3684
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
Jun 15 '06 #2
Works like a charm. Thanks! Wher can I find documentation on using these
Javascript methods and properties like document.getElementById and value?
Thanks

"David Hogue" wrote:
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

Jun 15 '06 #3
Also, how can I reset a value to clear the textbox?
Do I use

document.getElementById('<%= Textbox1.ClientID %>').value="";

Thanks

"David Hogue" wrote:
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

Jun 15 '06 #4
Chris wrote:
Works like a charm. Thanks! Wher can I find documentation on using these
Javascript methods and properties like document.getElementById and value?
Here's a few I use from time to time:

http://www.quirksmode.org/
http://developer.mozilla.org/en/docs/JavaScript
http://msdn.microsoft.com/workshop/a...lementbyid.asp
http://www.w3.org/DOM/
Also, how can I reset a value to clear the textbox?
Do I use

document.getElementById('<%= Textbox1.ClientID %>').value="";
That should work just fine.
Thanks


Happy to help

--
David Hogue
Jun 15 '06 #5
Thanks. Excellent resource.

"David Hogue" wrote:
Chris wrote:
Works like a charm. Thanks! Wher can I find documentation on using these
Javascript methods and properties like document.getElementById and value?


Here's a few I use from time to time:

http://www.quirksmode.org/
http://developer.mozilla.org/en/docs/JavaScript
http://msdn.microsoft.com/workshop/a...lementbyid.asp
http://www.w3.org/DOM/
Also, how can I reset a value to clear the textbox?
Do I use

document.getElementById('<%= Textbox1.ClientID %>').value="";


That should work just fine.
Thanks


Happy to help

--
David Hogue

Jun 15 '06 #6
Hi,

Chris wrote:
Also, how can I reset a value to clear the textbox?
Do I use

document.getElementById('<%= Textbox1.ClientID %>').value="";

Thanks


Exactly.

HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch
Jun 15 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Megha Vishwanath | last post by:
Hi, We have an application where my clients may be at different timezones. I need to validate time across the timezones with javascript. The date object in JavaScript does not allow me to get...
3
by: Steve | last post by:
Hi, I have a nice little script that works well displaying images on my website. It's a script where if you clik a thumbnail image a pop up window opens that contains a larger version of the same...
5
by: TrvlOrm | last post by:
HI There, I have been struggling with JavaScript code for days now, and this is my last resort! Please help... I am trying to create a JavaScript slide show with links for Next Slide,...
14
by: J. Makela | last post by:
Hallo. This should be a pretty entertaining question for you *real* javascript writers.. I, being the lowly photoshop guy at an ad agency made the mistake of actually saying "HTML" in a...
35
by: Boobie | last post by:
I need to escape HTML chracters so <test> --> &lt;test&gt; Looks like there is no built-in JS function...anyone got one handy ? thanks
0
by: dnphamus13 | last post by:
I'm new to this and drowning right now. I would like to put my database online for viewing. I managed to do the filtering but i need to do PAGING as the XML doc get bigger. From what i understand...
9
by: Mickey Segal | last post by:
The long-simmering Eolas patent dispute: http://www.microsoft.com/presspass/press/2003/oct03/10-06EOLASPR.mspx has led to an optional Microsoft Update: http://support.microsoft.com/kb/912945/en-us...
7
by: fox | last post by:
Hi, Lacking javascript knowledge, I just realized why my project has a bug. I am using ASP to loop through a set of records while it creates URLs with a querystring that has a single value pair....
8
by: | last post by:
The problem lies here eval("document.TeeForm.amt.value(S+M)"); S and M suppose to add up and the total suppose to appear on the AMT field but it didn't. Any help? ...
22
by: the_grove_man | last post by:
I purchased a book titled "Pro ASP.NET 2.0" to get up to speed on web stuff because I ususally do Windows Form Applications.. But in the first chapters I was reading this week it brought to mind...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.