Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

HTML Forum


You are currently viewing our HTML Forum as a guest. Please register to participate.
Login



Post a Project »

Find a Professional HTML Freelancer!

Find a Freelancer to help you with your HTML projects

FREE Outsourcing eBook!

Reply
Text Box Help - How do you make 2 textboxs that act as 1?
Old 05-21-2009, 08:56 PM Text Box Help - How do you make 2 textboxs that act as 1?
Physicsguy's Avatar
404 - Title not found

Posts: 919
Name: Scott Kaye
Location: Ontario
Trades: 0
I am trying to make 2 textboxes that if you type something in on one of them, it also appears in the other, and if you try to change it, it changes them both.

How do you do this? Thanks >)

I've tried making two textboxes with the same name, but that doesn't work...
__________________
Check out my
Please login or register to view this content. Registration is FREE
or my
Please login or register to view this content. Registration is FREE
!
Physicsguy is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-21-2009, 10:09 PM Re: Text Box Help - How do you make 2 textboxs that act as 1?
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
You'll need JavaScript. This code does it:

HTML Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <script type="text/javascript">
      function syncTextAreas(source) {
        if (source.id == "textarea_1") {
          document.getElementById('textarea_2').value = source.value;
        } else if (source.id == "textarea_2") {
          document.getElementById('textarea_1').value = source.value;
        }
      }
    </script>
  </head>
  <body>
    <textarea id="textarea_1" onkeyup="syncTextAreas(this);"></textarea>
    <textarea id="textarea_2" onkeyup="syncTextAreas(this);"></textarea>
  </body>
</html>
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 05-22-2009, 05:12 PM Re: Text Box Help - How do you make 2 textboxs that act as 1?
Physicsguy's Avatar
404 - Title not found

Posts: 919
Name: Scott Kaye
Location: Ontario
Trades: 0
Thanks a lot! I hope it works with input fields!

EDIT: Yep, it does! THANK YOU SO MUCH!
__________________
Check out my
Please login or register to view this content. Registration is FREE
or my
Please login or register to view this content. Registration is FREE
!

Last edited by Physicsguy; 05-22-2009 at 05:14 PM..
Physicsguy is offline
Reply With Quote
View Public Profile
 
Old 05-23-2009, 08:43 AM Re: Text Box Help - How do you make 2 textboxs that act as 1?
Physicsguy's Avatar
404 - Title not found

Posts: 919
Name: Scott Kaye
Location: Ontario
Trades: 0
I have encountered a problem.

I want to have 4 synced textboxes, but not all the same.

For example, this is what I want:

You type in something in textarea_1, say you type in "Hello", and it syncs with textarea_2, so now they both say "Hello". That's what the script does above.

Then, you type in something in textarea_3, say you type in "Hi, there", and it syncs with textarea_4, so now they both say "Hi, there". How do you do this?

Thanks

Sorry for double-post, but I couldn't post it in an edit above since this thread is old and nobody would check it. So sorry.

Is what I'm asking even possible? I've fiddled around, to no avail...
__________________
Check out my
Please login or register to view this content. Registration is FREE
or my
Please login or register to view this content. Registration is FREE
!

Last edited by Physicsguy; 05-23-2009 at 08:45 AM..
Physicsguy is offline
Reply With Quote
View Public Profile
 
Old 05-23-2009, 09:38 AM Re: Text Box Help - How do you make 2 textboxs that act as 1?
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
Please post code demonstrating what you tried.
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 05-23-2009, 09:42 AM Re: Text Box Help - How do you make 2 textboxs that act as 1?
Physicsguy's Avatar
404 - Title not found

Posts: 919
Name: Scott Kaye
Location: Ontario
Trades: 0
Well, I tried just repeating the code:

Code:
<script type="text/javascript">
      function syncTextAreas(source) {
        if (source.id == "textarea_1") {
          document.getElementById('textarea_2').value = source.value;
        } else if (source.id == "textarea_2") {
          document.getElementById('textarea_1').value = source.value;
        }
      }
    </script>

<script type="text/javascript">
      function syncTextAreas(source) {
        if (source.id == "textarea_3") {
          document.getElementById('textarea_4').value = source.value;
        } else if (source.id == "textarea_4") {
          document.getElementById('textarea_3').value = source.value;
        }
      }
    </script>
But that didn't work...

So I tried:

Code:
<script type="text/javascript">
      function syncTextAreas(source) {
        if (source.id == "textarea_1") {
          document.getElementById('textarea_2').value = source.value;
        } else if (source.id == "textarea_2") {
          document.getElementById('textarea_1').value = source.value;
        if (source.id == "textarea_3") {
          document.getElementById('textarea_4').value = source.value;
        } else if (source.id == "textarea_4") {
          document.getElementById('textarea_3').value = source.value;
        }
      }
        }
      }
    </script>
And that didn't work...

I don't get it... The first one makes textareas 3 and 4 synced, but not 1 and 2, and the one you gave syncs 1 and 2, and the second one I posted doesn't work at all...

AARRGGHH my brain hurts
__________________
Check out my
Please login or register to view this content. Registration is FREE
or my
Please login or register to view this content. Registration is FREE
!

Last edited by Physicsguy; 05-23-2009 at 09:47 AM..
Physicsguy is offline
Reply With Quote
View Public Profile
 
Old 05-23-2009, 09:47 AM Re: Text Box Help - How do you make 2 textboxs that act as 1?
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
You just had some of your if/else statements crossed:

HTML Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <script type="text/javascript">
      function syncTextAreas(source) {
        if (source.id == "textarea_1") {
          document.getElementById('textarea_2').value = source.value;
        } else if (source.id == "textarea_2") {
          document.getElementById('textarea_1').value = source.value;
        } else if (source.id == "textarea_3") {
          document.getElementById('textarea_4').value = source.value;
        } else if (source.id == "textarea_4") {
          document.getElementById('textarea_3').value = source.value;
        }
      }

    </script>
  </head>
  <body>
    <textarea id="textarea_1" onkeyup="syncTextAreas(this);"></textarea>
    <textarea id="textarea_2" onkeyup="syncTextAreas(this);"></textarea>
    <textarea id="textarea_3" onkeyup="syncTextAreas(this);"></textarea>
    <textarea id="textarea_4" onkeyup="syncTextAreas(this);"></textarea>
  </body>
</html>
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 05-23-2009, 09:48 AM Re: Text Box Help - How do you make 2 textboxs that act as 1?
Physicsguy's Avatar
404 - Title not found

Posts: 919
Name: Scott Kaye
Location: Ontario
Trades: 0
Oooohhhhh thank you so much!
__________________
Check out my
Please login or register to view this content. Registration is FREE
or my
Please login or register to view this content. Registration is FREE
!
Physicsguy is offline
Reply With Quote
View Public Profile
 
Old 05-23-2009, 03:11 PM Re: Text Box Help - How do you make 2 textboxs that act as 1?
wt.canton's Avatar
Novice Talker

Posts: 5
Name: James Canton
Trades: 0
Quote:
Originally Posted by Physicsguy View Post
Thanks a lot! I hope it works with input fields!

EDIT: Yep, it does! THANK YOU SO MUCH!
I agree, this is really **** handy; thanks a lot!
wt.canton is offline
Reply With Quote
View Public Profile
 
Old 05-23-2009, 09:06 PM Re: Text Box Help - How do you make 2 textboxs that act as 1?
Physicsguy's Avatar
404 - Title not found

Posts: 919
Name: Scott Kaye
Location: Ontario
Trades: 0
Quote:
Originally Posted by wt.canton View Post
I agree, this is really **** handy; thanks a lot!
This will probably get a lot of visits from Google! Might want to put a few ads on this post
__________________
Check out my
Please login or register to view this content. Registration is FREE
or my
Please login or register to view this content. Registration is FREE
!
Physicsguy is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Text Box Help - How do you make 2 textboxs that act as 1?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.89803 seconds with 12 queries