Hello! I want some JavaScript (or any other client-side) solution for my problem thatdescribed 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 |
![]() |
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 |
![]() |
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:
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 |
![]() |
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:
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 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 |
![]() |
Sorry, i missed that and thought a round trip is needed.
![]() |
0 |
![]() |
Hey guys!
Did anyone found a solution algorithm to forward the dates correctly?
Thanks!
![]() |
0 |
![]() |
<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 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 |
![]() |
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 |
![]() |