SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2006
    Location
    Hyderabad, India
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Copying data from one text box to another in html automatically.

    Hi,

    I want to copy data from one text box to another in html automatically i.e., if I edit one textbox the other should display the same simultaneously. Can someone help me...

    Thanks in advance.

    With Regards,
    Prasanthi

  2. #2
    SitePoint Wizard silver trophybronze trophy Stormrider's Avatar
    Join Date
    Sep 2006
    Location
    Nottingham, UK
    Posts
    3,133
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You'll need to use javascript with onchange, or possibly onkeypress / onkeydown or something.

    I'm no javascript expert, but...

    HTML Code:
    <form name="theform" action="something" method="something" />
     <input type="text" name="input1" onkeypress="document.theform.input2.value = this.value" />
     <input type="text" name="input2" />
    </form>
    or something?

  3. #3
    SitePoint Enthusiast
    Join Date
    Jul 2006
    Location
    Hyderabad, India
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks so much...

    at the same time is it possible that we can display the same data in more than one textbox(without using functions)... if so can you just show me an example please.

    Thanks once again.
    With Regards,
    Prasanthi

  4. #4
    SitePoint Wizard silver trophybronze trophy Stormrider's Avatar
    Join Date
    Sep 2006
    Location
    Nottingham, UK
    Posts
    3,133
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    No, i would use a function for that then. You can put multiple commands separated by a semi-colon, but it can get a bit too long sometimes.

    Code:
    onkeypress="document.theform.input2.value = this.value; document.theform.input3.value = this.value; ... "
    Also, I think the best idea is to use a seperate script file rather than putting the javascript 'inline', but I'm not an expert on doing that either.

  5. #5
    SitePoint Wizard bronze trophy DaveWoods's Avatar
    Join Date
    Dec 2004
    Location
    Derbyshire - UK
    Posts
    2,651
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Also it's worth bearing in mind what will happen if the user doesn't have JavaScript.

    As a rule, you shouldn't use JavaScript for critical functionality so if this function is required in order for someone to fill out a form then I'd suggest using an alternative method.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •