2 Replies - 3226 Views - Last Post: 27 December 2011 - 02:04 AM

#1 notice88  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 87
  • Joined: 21-December 11

How can i display 2 textbox values into 1 textbox separated by space?

Posted 26 December 2011 - 10:17 PM

here is my script
window.onload = function () {
  var first_comp_lastname = document.getElementById('first_comp_lastname'),
  	  first_comp_firstname = document.getElementById('first_comp_firstname'),
      
      second_comp_name = document.getElementById('second_comp_name');
		
		var comp_name=new Array();
		comp_name[0]=first_comp_firstname.value;
		comp_name[2]=first_comp_lastname.value;      
		name=comp_name.join(" ");


  	 first_comp_firstname.onkeyup = function () { // or first.onchange
	 second_comp_name.value =  name;
	 
	
	};
};



here is my html code... just only the textbox
<input type="text" name="complainant_lastname" maxlength="150" size="15" id="first_comp_lastname">
<input type="text" name="complainant_firstname" maxlength="150" size="15" id="first_comp_firstname">

<input type="text" name="complainant_name" maxlength="150" size="25" id="second_comp_name">



i can change the second_comp_name.value = name; into second_comp_name.value = first_comp_firstname.value; its working but what i want is to get the values from first_comp_firstname and first_comp_lastname separated by space into second_comp_name. I tried join method to do that but its not working, when i type, nothing happens to the second_comp_name.

Is This A Good Question/Topic? 0
  • +

Replies To: How can i display 2 textbox values into 1 textbox separated by space?

#2 arvindthakur  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 133
  • Joined: 07-June 11

Re: How can i display 2 textbox values into 1 textbox separated by space?

Posted 26 December 2011 - 11:43 PM

Well notice88,

My english language is not so good. But what i get from your question is you want to combine the values of two textboxes and display them into third one separated by space.Like if I am putting abc in first textbox and xyz in secondd one then after leaving second textbox we should get abc xyz. For this I have just write a simple example. Please look the below code.

 <html>
 <head>
  <script langugae="javascript">
   function doCombine()
   {
       document.getElementById('txt3').value = document.getElementById('txt1').value + " " +
	   document.getElementById('txt2').value;
   }
  </script>
 </head>
 <body>
  <input type="text" id="txt1" name="txt1" /> + 
  <input type="text" id="txt2" name="txt2" onchange="doCombine();" /> =
  <input type="text" id="txt3" name="txt3" />
 </body>
</html>



Thanks,

Arvind
Was This Post Helpful? 1
  • +
  • -

#3 notice88  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 87
  • Joined: 21-December 11

Re: How can i display 2 textbox values into 1 textbox separated by space?

Posted 27 December 2011 - 02:04 AM

View Postarvindthakur, on 26 December 2011 - 11:43 PM, said:

Well notice88,

My english language is not so good. But what i get from your question is you want to combine the values of two textboxes and display them into third one separated by space.Like if I am putting abc in first textbox and xyz in secondd one then after leaving second textbox we should get abc xyz. For this I have just write a simple example. Please look the below code.

 <html>
 <head>
  <script langugae="javascript">
   function doCombine()
   {
       document.getElementById('txt3').value = document.getElementById('txt1').value + " " +
	   document.getElementById('txt2').value;
   }
  </script>
 </head>
 <body>
  <input type="text" id="txt1" name="txt1" /> + 
  <input type="text" id="txt2" name="txt2" onchange="doCombine();" /> =
  <input type="text" id="txt3" name="txt3" />
 </body>
</html>



Thanks,

Arvind


Thanks dude, thats exactly what i wanted. maybe im the one whos not too good in english. thankyou :online2long:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1