473,396 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

JavaScript coding to swap the content of two text box elements

hi everyone....
i want the coding help in Javascript to "swap the content of two Textbox elements" ..Kindly reply me.....
Jul 15 '08 #1
11 11039
Hi,

Please explain clearly what u want exactly. swap the text in textbox means?
Jul 15 '08 #2
dmjpro
2,476 2GB
hi everyone....
i want the coding help in Javascript to "swap the content of two Textbox elements" ..Kindly reply me.....
Expand|Select|Wrap|Line Numbers
  1. <input type=text id=text_id1 value='' />
  2. <input type=text id=text_id2 value='' />
  3.  
Expand|Select|Wrap|Line Numbers
  1. function swap_content(){
  2. var tmp = document.getElementById('text_id1').value;
  3. document.getElementById('text_id1').value = document.getElementById('text_id2').value;
  4. document.getElementById('text_id2').value = tmp;
  5. }
  6.  
Debasis Jana
Jul 15 '08 #3
Expand|Select|Wrap|Line Numbers
  1. <input "type="text" name="text_id1" id="text_id1" value='' access here value from the PHP or other,,   eg. echo"$_POST['text_id1']";  "/>
  2. <input type="text" name="text_id1" id="text_id2" value='' access here value from the PHP or other eg. echo"$_POST['text_id2']";  ""//>
  3. <input type="submit" value="swap" onClick="swap_content("text_id1","text_id2");"> 
  4.  
Expand|Select|Wrap|Line Numbers
  1. function swap_content(id1,id2){
  2. var tmp = document.getElementById('text_id1').value;
  3. document.getElementById('text_id1').value = document.getElementById('text_id2').value;
  4. document.getElementById('text_id2').value = tmp;
  5. }
  6.  
I think this will be work good .


dkyadav80
Jul 15 '08 #4
acoder
16,027 Expert Mod 8TB
I think this will be work good .
There are one or two problems: you've got double quotes within double quotes, and you're passing the ids but not making use of them.
Jul 15 '08 #5
i want to swap the content of two text box by using javascript...I have written code as follows,but its not working....kindly reply me any one as soon as possible....

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <input "type="text" name="text_id1" id="text_id1" value='a' >
  3. <input type="text" name="text_id1" id="text_id2" value='b' >
  4. <input type="submit" value="swap" onClick=swap_content(text_id1,text_id2)>
  5. <script type="javascript/text">
  6. function swap_content(id1,id2)
  7. {
  8.  var tmp = document.getElementById(text_id1).value;
  9.  document.getElementById(text_id1).value = document.getElementById(text_id2).value;
  10. document.getElementById(text_id2).value = tmp;
  11. }
Jul 17 '08 #6
i want to swap the content of two text box by using javascript...I have written code as follows,but its not working....kindly reply me any one as soon as possible....

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <input "type="text" name="text_id1" id="text_id1" value='a' >
  3. <input type="text" name="text_id1" id="text_id2" value='b' >
  4. <input type="submit" value="swap" onClick=swap_content(text_id1,text_id2)>
  5. <script type="javascript/text">
  6. function swap_content(id1,id2)
  7. {
  8. var tmp = document.getElementById(text_id1).value;
  9. document.getElementById(text_id1).value = document.getElementById(text_id2).value;
  10. document.getElementById(text_id2).value = tmp;
  11. }
Jul 17 '08 #7
hsriat
1,654 Expert 1GB
[html]<input type="text" name="text_id1" id="text_id1" value="a" >
<input type="text" name="text_id2" id="text_id2" value="b" >
<input type="submit" value="swap" onclick="swap_content('text_id1','text_id2')">
<script type="text/javascript">
function swap_content(id1,id2)
{
var tmp = document.getElementById(id1).value;
document.getElementById(id1).value = document.getElementById(id2).value;
document.getElementById(id2).value = tmp;
}
</script>[/html]

I've underlined the part of the code where you had made some mistakes.
Jul 17 '08 #8
Thank U...I got the output....

[html]<input type="text" name="text_id1" id="text_id1" value="a" >
<input type="text" name="text_id2" id="text_id2" value="b" >
<input type="submit" value="swap" onclick="swap_content('text_id1','text_id2')">
<script type="text/javascript">
function swap_content(id1,id2)
{
var tmp = document.getElementById(id1).value;
document.getElementById(id1).value = document.getElementById(id2).value;
document.getElementById(id2).value = tmp;
}
</script>[/html]

I've underlined the part of the code where you had made some mistake.
Jul 17 '08 #9
debasisdas
8,127 Expert 4TB
question moved to javascript forum.
Jul 17 '08 #10
hsriat
1,654 Expert 1GB
question moved to javascript forum.
Question already there in JS forum. Both threads just need to be merged.
Jul 17 '08 #11
acoder
16,027 Expert Mod 8TB
sreekandan, as a full member now, you should know that we expect your code to be posted in [code] tags (See How to Ask a Question).

This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

Please use the tags in future.

Also, do not double/triple post your questions. All duplicate threads have been merged.

MODERATOR.
Jul 17 '08 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Fabian | last post by:
This javascript is meant for learning language vocabulary, specifically colours on this example. However, when I use images in the mtWord array, it breaks when checking for correct answers. It...
53
by: Cardman | last post by:
Greetings, I am trying to solve a problem that has been inflicting my self created Order Forms for a long time, where the problem is that as I cannot reproduce this error myself, then it is...
7
by: Trvl Orm | last post by:
I am working with 2 frames, Left and Right and the main code is in the left frame, which has been attached. Can someone please help me with this code. I am new to JavaScript and can't figure it...
13
by: amykimber | last post by:
Hi all, I know I'm doign something really daft, but I can't get this to work... I have a form with a bunch of inputs called ship_owner - why the ? Because I'm submitting this page though php...
2
by: William van Zwanenberg | last post by:
Hi there, I wonder if you guys can help. I'm currently experiencing some coding problems what with trying to use PHP and javascript in tandem. What I'm ultimately trying to achieve is use...
20
by: alice | last post by:
I'm doing some text swapping with javascript, got it working fine, but I would like the line to have line breaks and being a beginner, I don't even know if this is possible. So I have a line like...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.