How to change txt2.text when the txt1's.text changes using JavaScript?

Hello! I want some JavaScript (or any other client-side) solution for my problem that

described here:  http://forums.asp.net/p/1382766/2930267.aspx

 

In a few words, my problem is that i don't know the way to change the txt2.text value

when the txt1.text value changes...

 

Please read the http://forums.asp.net/p/1382766/2930267.aspx first...

I want only JavaScript solution...

Thank you very much!

0
MinimalTech
2/10/2009 11:57:54 AM
asp.net.client-side 24353 articles. 1 followers. Follow

11 Replies
742 Views

Similar Articles

[PageSpeed] 34

Like this?

<input type="text" id="TextBox1" name="TextBox1" onchange="textBox1OnChange(this);" runat="server" />
<input type="text" id="TextBox2" name="TextBox2" runat="server" />

<script type="text/javascript">
<!--
function textBox1OnChange(elementRef)
{
 document.getElementById('TextBox2').value = 'what-ever-you-want-to-change-it-to;
}
// -->
</script>

Actually onblur would probably be better to use than onchange since onchange doesn't fire if the user pastes a value into the TextBox.

NC...

0
NC01
2/10/2009 1:47:52 PM

hI

Try this code

<asp:TextBox ID="txtURL" runat="server" ReadOnly="true" BorderStyle="None" BorderWidth="0"

Width="350px"></asp:TextBox>

<asp:TextBox ID="txtCategoryOther" Width="350px" runat="server" Text='<%#Bind("CategoryOther")%>'></asp:TextBox>

--------------------//*//------------------

Dim txtInput As TextBox = TryCast(FindControl("txtCategoryOther"), TextBox)

Dim txtOutput As TextBox = TryCast(FindControl("txtURL"), TextBox)

txtInput.Attributes.Add("onKeyUp", "javascript:document.getElementById('" + txtOutput.ClientID + "').value=document.getElementById('" + txtInput.ClientID + "').value;")

maha...

 

0
magendran
2/10/2009 2:21:26 PM

magendran:

hI

Try this code

<asp:TextBox ID="txtURL" runat="server" ReadOnly="true" BorderStyle="None" BorderWidth="0"

Width="350px"></asp:TextBox>

<asp:TextBox ID="txtCategoryOther" Width="350px" runat="server" Text='<%#Bind("CategoryOther")%>'></asp:TextBox>

--------------------//*//------------------

Dim txtInput As TextBox = TryCast(FindControl("txtCategoryOther"), TextBox) Dim txtOutput As TextBox = TryCast(FindControl("txtURL"), TextBox)

txtInput.Attributes.Add("onKeyUp", "javascript:document.getElementById('" + txtOutput.ClientID + "').value=document.getElementById('" + txtInput.ClientID + "').value;")

maha...

Isn't that just setting the 2 TextBoxes to the same value?

NC...

 

0
NC01
2/10/2009 3:16:37 PM

Hello,

I have nothing to add NC01's code which should work for you but just to remind, you cannot do what you aim to do with server-side (asp)  textboxes. So you should redesign your page and flow in order to use basic HTML text inputs (if you are using server controls)

0
sheyda
2/10/2009 3:30:34 PM

sheyda:

Hello,

I have nothing to add NC01's code which should work for you but just to remind, you cannot do what you aim to do with server-side (asp)  textboxes. So you should redesign your page and flow in order to use basic HTML text inputs (if you are using server controls)

Why wouldn't it work with ASP:TextBoxes? The end up rendering the exact same in the HTML.

For instance, this works just as well:

<asp:TextBox ID="TextBox1" onchange="textBox1OnChange(this);" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

<script type="text/javascript">
<!--
function textBox1OnChange(elementRef)
{
 document.getElementById('<%= TextBox2.ClientID %>').value = 'what-ever-you-want-to-change-it-to;
}
// -->
</script>

Note that I attached the event handler to the element in the HTML declaration. This will work, but will produce a compiler warning. The proper way to do this for a server control is in the Page_Load handler of the server-side code like this:
 TextBox1.Attributes.Add("onchange", "textBox1OnChange(this);");

NC...

0
NC01
2/10/2009 3:39:57 PM

NC01 you're my hero!! Your scripts works always perfect!

I made a little change in the "textBox1OnChange()" function so that the "txt2" to take the value of txt1 when the txt1 changes.

All works fine at that point. My other question, is the below:

 The txt1 takes the Date from the CalendarExtender1 (please read my other post at "http://forums.asp.net/p/1382766/2930267.aspx" for more info),

and i want, after the txt1 changes, the txt2 to show the next date of the moth. If there is not next date on the current month (e.x. lets say that today is 31),

 i want the txt2 to show the 1st of the next month e.t.c....

How can i achieve that? With VB i know what to do but with JavaScript i don't.  Do you have any ideas?

Thank you very much!

 

0
MinimalTech
2/10/2009 8:11:31 PM

Sorry, i missed that and thought a round trip is needed.

0
sheyda
2/11/2009 6:59:28 AM

 Hey guys!

Did anyone found a solution algorithm to forward the dates correctly?

Thanks!

0
MinimalTech
2/11/2009 10:01:46 AM

<script type="text/javascript">
<!--
function textBox1OnChange(elementRef)
{
 var dateString = document.getElementById('<%= TextBox1.ClientID %>').value;

 var dateValue = new Date(dateString);
 var monthValue = dateValue.getMonth() + 1;
 var dayValue = dateValue.getDate() + 1;
 var yearValue = dateValue.getFullYear();

 var newDate = new Date(Date.parse(monthValue + '/' + dayValue + '/' + yearValue));
 monthValue = newDate.getMonth() + 1;
 if ( monthValue < 10 )
  monthValue = '0' + monthValue;
 dayValue = newDate.getDate();
 if ( dayValue < 10 )
  dayValue = '0' + dayValue;
 yearValue = newDate.getFullYear();

 document.getElementById('<%= TextBox2.ClientID %>').value = monthValue + '/' + dayValue + '/' + yearValue;
}
// -->
</script>

Of course, no validations are included. The value from TextBox1 should always be validated first as to being a valid date.

NC...

0
NC01
2/11/2009 1:49:00 PM

 NC01 you are the boss!!

 Your script is true again and runs correctly! Don't worry about data validations, i have take care of them!!

Thank you very much!

0
MinimalTech
2/11/2009 6:46:40 PM

No problem my friend. Just make sure that the TextBox is formatted "dd/mm/yyyy" and is a valid date, and you should have no problems.

NC...

 

0
NC01
2/11/2009 7:04:11 PM
Reply:

Similar Artilces:

Can you change a linkbutton's text using client side javascript?
I have a linkbutton which opens a new window. When the user closes the new window, I want to change the text of the original linkbutton. The issue isn't the popup window since know how to use window.opener. The problem is that I don't know how to use javascript to change the inner text of the linkbutton which I know is rendered as anchor tags. Any suggestions? Hi, on the Page where the LinkButton is, you can output the client-side ID of the LinkButton with it's ClientID property assuming you have <asp:LinkButton ID="LinkButton1" runat="server" Text="Hello" />So you could ou...

How to change txt2.text when the txt1's date of AJAX CalendarExtender changes?
 Hi!I  have two text boxes inside my aspx page: a) the "txt1" and b) the "txt2".Both text boxes has CalendarExtender controls attached: a) the txt1 has the "CalendarExtender1" and b) the txt2 has the"CalendarExtender2".All i want, is this:Using client-side script (or other method without postbacks), i want when the user chooses a date from CalendarExtender1,the same date plus a day front to go to the txt2.For example:If the user choose 03/28/2009 in the CalendarExtender1, i want the value of the txt2 to be the 03/29/2009....Also, if the month...

Can I change a treeview's text size depending on what my browser's text size is set to?
I'm using a treeview on a .net 2.0 page and all is working fine with it in Internet Explorer.  However if I go to View -->  Text Size --> Largest on my browser's menu, all the text on my page appears huge apart from the text in the treeview which remains the same size as it always was.  Is there a way to fix this so that this text will also increase in size? Many Thanks. Make sure the font size is not set in the control.  And use css to help moderate your pages look and feel. HTH,Joe JohnstonIf a picture is worth a 1000 words, a sample application ...

How to restore label's text across postbacks when it is changed by client-side script?
Hello all,I have a page that uses AJAX to check info entered in textboxes and display results by changing the text of labels underneath the textboxes. Since label's value/text is not submitted by the form, I use hidden fields (that are updated together with the labels) to restore the text of labels across postbacks. The question is: is there any nicer way of doing that? Maybe I should use some other control, instead of labels, the value of which is submitted?Thank you.  It depends on what your ajax call is doing.  If it's a webservice call, or any of the ajax framework...

text change, why wont you text change!!!!
Hi i've got a huge form with loadsa recordsets that populate text boxes, AND I MEAN LOADS!!!!It involves some calculationsI have text1.text which goes away and changes text2.text which is fine, but in text2.text i have another on text change thingy which it wont call :(any one have any ideas : )also does any one know how i could call a txt change, so it does the call total a. dont know if thats possible as well. Private Sub txtShare_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtShare.TextChanged Call Total_A() End SubThank you if any one one could help...

how to change a button's text in javascript
I have a button called btnFailureReport. Once a javascript function was called, I want the text of the btnFailureReport can be changed. Please see the code below. The problem is the "text" of the btnFailureReport was changed only for look. If I want to save the text to the database, I found the text is still the old text. So I put the two alert box (commented out) in the function to test. The result for the first one (ctrl.value) is the "hello" which is right. But the result for the second one (ctrl.text) is "undefined", which means the "text" was not...

change menu's property Target in client-side (javascript)
Hi all ! I need to be able to change the target of my menu (regular asp.net control) in client-side using javascript. Does anyone have a clue or tip? Thanks a lot !We are here to learn, and teach whenever possible... Since every server side control renders finally as HTML, you must be able to access each HTML element rendered using javascript and do any changes but, I did not understand what Menu target means. other than that you can view source to see how the Menu control is rendered and use js to modify any part thereof. Thanks,RavikanthPlease "Mark as Answer&q...

Does anyonw know how to fire a JAVAscript function when the TextBox's Text have been changed.
Does anyonw know how to fire a JAVAscript function when the TextBox's Text have been changed. Hello there,Hope this could be helpful  TexBoxID.Attributes.Add("fun1", "return JavaScriptFunctionName(event)"); fun1 is the name of event which is fired when text of text box is changed i.e. textchanged event. Thank you,   Thanks,Mark as Answer if it helps u....Devaang Hi,Try this<script language='javascript' type='text/javascript' > function txtChange(para){    alert(para.value) } <...

User's Name Changed
We are using Groupwise 5.5 I have a user that recently married. I have created a Groupwise alias for the new name, but how do I go about changing the Groupwise Object/User ID and NDS account ID and keep their email account intact? Thanks, J.Jensen Jeff, you can simply rename the Groupwise account. No mail loss. Uwe -- Novell Support Connection Volunteer SysOp Please don't send me support related e-mail unless I ask you to do so. ...

I'd like to change CrystalReportView control text's to other language
Hi, all I'd like to change CrystalReportViewer control to other language (for example Arabia Language Change zoom to word in other language) Can I do that? How? Sorry, My English language is bad but I like learn The .NET Technology and all my friends are not know the computer how to work:(. Thanks for all. dot Net Love....

Can't change the text in a text box?
I'm sure I'm missing something obvious, but I can't figure this out.  I simply want to read in the text from a file, and display it in a textbox.  The user should be able to change the text, and save it back to the original file (overwriting the original text).This is what I have:<body>    <form id="form1" runat="server">    <div align="center">        <b>Enter/Edit text for the Autoresponder</b>        <asp:TextBo...

Changing the text of a asplabel using javascript
Hi: I have a label in a ascx. and a list box. I want to be able to change the text of the label when the users change their listbox selection. I can get the event handler to fire, get the value of the selected inex  but I cant get the value of the label to change. Please help. thanks! KP Are you using the Event Handler for DropDown_SelectedIndexChanged to change the value of the label? Please post your server side code here, which helps us to answer your question.My ASP.NET blog ~God doesn't play dice... heya, here is the poor mans' version of doing what you got in...

superreview granted: [Bug 224546] Change Win 'Regional Settings' -> lose button functions & text : [Attachment 136434] update with smontagu's concerns addressed
David Baron <dbaron@dbaron.org> has granted Jungshik Shin <jshin@mailaps.org>'s request for superreview: Bug 224546: Change Win 'Regional Settings' -> lose button functions & text http://bugzilla.mozilla.org/show_bug.cgi?id=224546 Attachment 136434: update with smontagu's concerns addressed http://bugzilla.mozilla.org/attachment.cgi?id=136434&action=edit ------- Additional Comments from David Baron <dbaron@dbaron.org> >Index: intl/locale/src/windows/nsIWin32LocaleImpl.cpp > struct iso_pair > { > char* iso_code; How ab...

superreview requested: [Bug 224546] Change Win 'Regional Settings' -> lose button functions & text : [Attachment 136434] update with smontagu's concerns addressed
Jungshik Shin <jshin@mailaps.org> has asked Christopher Blizzard <blizzard@mozilla.org> for superreview: Bug 224546: Change Win 'Regional Settings' -> lose button functions & text http://bugzilla.mozilla.org/show_bug.cgi?id=224546 Attachment 136434: update with smontagu's concerns addressed http://bugzilla.mozilla.org/attachment.cgi?id=136434&action=edit ------- Additional Comments from Jungshik Shin <jshin@mailaps.org> asking for r/sr. perhaps not this weekend although i'd not complain if you could review this weekend :-) ...

Web resources about - How to change txt2.text when the txt1's.text changes using JavaScript? - asp.net.client-side

JavaScript Kit- Your comprehensive JavaScript, DHTML, CSS, and Ajax stop
Your comprehensive JavaScript, DHTML, CSS, and Ajax stop

Let's Code: Test-Driven Javascript by James Shore — Kickstarter
James Shore is raising funds for Let's Code: Test-Driven Javascript on Kickstarter! A screencast series focusing on rigorous, professional Javascript ...

Eloquent JavaScript: A Modern Introduction to Programming
... and pragmatics. I loved the tutorial-style game-like program development. This book rekindled my earliest joys of programming. Plus, JavaScript! ...

JavaScript - Wikipedia, the free encyclopedia
programming styles. JavaScript was formalized in the ECMAScript language standard and is primarily used in the form of client-side JavaScript ...

Open Directory - Computers: Programming: Languages: JavaScript: Tools: Obfuscators
... editor - report abuse/spam - help the entire directory only in Tools/Obfuscators Description Top : Computers : Programming : Languages : JavaScript ...

Facebook Open-Sources JavaScript Static-Type Checker Flow
The latest software to be open-sourced by Facebook is Flow , a static-type checker for JavaScript . (more…) New Career Opportunities Daily: ...

Under the Hood: The JavaScript SDK - The use of polyfills - Facebook
Facebook Engineering hat eine Notiz mit dem Titel Under the Hood: The JavaScript SDK - The use of polyfills geschrieben. Du kannst den vollständigen ...

JavaScript
The Facebook SDK for JavaScript provides a rich set of client-side functionality for adding Social Plugins, making API calls and implementing ...

Facebook App Devs Get Javascript
It has been an oft-lamented fact of the Facebook Platform thus far in its life that, in order to use all but the most simple of Javascript functionality–the ...

Badass JavaScript (@badass_js) on Twitter
WebGLWorker is an open source library that allows using WebGL from Web Workers. Great work as always from @kripken . blog.mozilla.org/research/2014/… ...

Resources last updated: 11/29/2015 4:12:43 PM