help with javascript

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

i need to use javascript in the following 2 situations but dont know how and
thanks in advance:

1. i have 2 textboxes and they usually contain the same information. when
the user starts entering data in the 1st textbox, the data should also appear
in the 2nd textbox. if needed, the user can modify the data in the 2nd
textbox.

2. i have a textbox and a control beside it. the textbox should have a max.
no. of char. allowed and the control beside it reminds the user how many more
chars. can be entered. as the user enters characters, the control starts
counting down. an example of this is Carfax's textbox for entering the VIN #.
 
Newbie,

I'm a little rusty on my Javascript. =)

For each of these, you will want to attach an event handler for the
textbox so that when it changes, your method is fired (look for an onChange
event). Then, in the event handler, you can modify the contents of the
other textbox, or get the length of the current text and set a label to that
number to show how many characters are typed.

Also, for textboxes, I believe you can set the length attribute in the
input tag to indicate the maximum length of the contents of the textbox.

Hope this helps.
 
Hi,

this is a C# NG, you would get a better answer at a javascript NG, take a
look at the onchange event of the input control

cheers,
 
Use the following code,
script:
<SCRIPT language="javascript">
function keyUp()
{
document.all("TextBox4").value = document.all("TextBox2").value;
document.all("TextBox5").value = 100 -
document.all("TextBox2").value.length;
}
</SCRIPT>
design:

<asp:TextBox id="TextBox2" runat="server" onkeyup="keyUp();"></asp:TextBox>
<asp:TextBox id="TextBox4" runat="server"></asp:TextBox>
<asp:TextBox id="TextBox5" runat="server"></asp:TextBox></form>
 
Back
Top