Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

how to change text box values

Posted on 2009-04-06
9
Medium Priority
?
241 Views
Last Modified: 2012-05-06
Hi,

am having a text box i want to load values to another text box eachtime the valueon the first text box changes.....its only changing after i change the text and click on the text box or press enter key...

but when i use select box its changing automatically am gettin prob with text box pls help....
0
Comment
Question by:whspider
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 2

Expert Comment

by:Jassimi
ID: 24084237
hi..
you can put this:
textbox2.text = textbox1.text
0
 
LVL 7

Expert Comment

by:Chandan_Gowda
ID: 24084247
use onTextChanged Event of the textbox,Write a javascript in onTextChanged event of textbox1
0
 

Author Comment

by:whspider
ID: 24084256
this is my code....

<script type="text/javascript">  
$(document).ready(function() {
$("input[@name='test1']").change(function()
{
if ($("input[@name='test1']:checked").val()=="0")
$("#cse_search").autocomplete(searchdata2);
else if ($("input[@name='test1']:checked").val()=="1")
 $("#cse_search").autocomplete(searchdata1);  
}
);
});


function getXMLHTTP() { //fuction to return the xml http object
            var xmlhttp=false;      
            try{
                  xmlhttp=new XMLHttpRequest();
            }
            catch(e)      {            
                  try{                  
                        xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
                  }
                  catch(e){
                        try{
                        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
                        }
                        catch(e1){
                              xmlhttp=false;
                        }
                  }
            }
                   
            return xmlhttp;
    }
      
function getCurrencyCode(strURL1)
{            
      var req1 = getXMLHTTP();            
      if (req1)
      {
            //function to be called when state is changed
            req1.onreadystatechange = function()
            {
                  //when state is completed i.e 4
                  if (req1.readyState == 4)
                  {                  
                        // only if http status is "OK"
                        if (req1.status == 200)
                        {                                    
                              document.getElementById('cur_code').value=req1.responseText;                                    
                        }
                        else
                        {
                              alert("There was a problem while using XMLHTTP:\n" + req1.statusText);
                        }
                  }                        
             }                  
             req1.open("GET", strURL1, true);
             req1.send(null);
      }                  
}      
</script>


<td colspan="9"><input type="text" id="cse_search" name="q" size="31" onblur="getCurrencyCode('code.php?local='+this.value)" /></td>
</tr>
<tr>

<td>Amt:  <input type="text" name="cur_code" size="7" id="cur_code" ></td>
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 3

Accepted Solution

by:
kingsob earned 1500 total points
ID: 24084303
is this what you are looking for?

you can change the event name to change the behaviour.. for example.. if you change it to onchange, it will update testbox 2 when you leave textbox 1
<html>
<head>
</head>
<body>
  <input id="text1" type="text" onkeyup="document.getElementById('text2').value = this.value;"/>
  <input id="text2" type="text" />
</body>
</html>

Open in new window

0
 

Author Comment

by:whspider
ID: 24084316
yes this is what...but when i use mouse its not working i want using mouse click also and key also
0
 
LVL 7

Expert Comment

by:Chandan_Gowda
ID: 24084317
<script type="text/javascript">  
$(document).ready(function() {
$("input[@name='test1']").change(function()
{
if ($("input[@name='test1']:checked").val()=="0")
$("#cse_search").autocomplete(searchdata2);
else if ($("input[@name='test1']:checked").val()=="1")
 $("#cse_search").autocomplete(searchdata1);  
}
);
});


function getXMLHTTP() { //fuction to return the xml http object
            var xmlhttp=false;      
            try{
                  xmlhttp=new XMLHttpRequest();
            }
            catch(e)      {            
                  try{                  
                        xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
                  }
                  catch(e){
                        try{
                        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
                        }
                        catch(e1){
                              xmlhttp=false;
                        }
                  }
            }
                   
            return xmlhttp;
    }
     
function getCurrencyCode(strURL1)
{            
      var req1 = getXMLHTTP();            
      if (req1)
      {
            //function to be called when state is changed
            req1.onreadystatechange = function()
            {
                  //when state is completed i.e 4
                  if (req1.readyState == 4)
                  {                  
                        // only if http status is "OK"
                        if (req1.status == 200)
                        {                                    
                              document.getElementById('cur_code').value=req1.responseText;                                    
                        }
                        else
                        {
                              alert("There was a problem while using XMLHTTP:\n" + req1.statusText);
                        }
                  }                        
             }                  
             req1.open("GET", strURL1, true);
             req1.send(null);
      }                  
}  
function populateAmount ()
{
      var txtboxamt=document.getElementById('cur_code')
      var txt1=document.getElementById('cse_search')
      //alert(txt1);
      txtboxamt.value=txt1.value
}    
</script>


<td colspan="9"><input type="text" id="cse_search" name="q" size="31" OnKeyup="populateAmount();" onblur="getCurrencyCode('code.php?local='+this.value)" /></td>
</tr>
<tr>

<td>Amt:  <input type="text" name="cur_code" size="7" id="cur_code" ></td>
0
 
LVL 3

Expert Comment

by:kingsob
ID: 24084320
you could add the code to a function, so you don't have to duplicate it
<html>
<head>
</head>
<body>
  <input id="text1" type="text" onkeyup="document.getElementById('text2').value = this.value;" onchange="document.getElementById('text2').value = this.value;"/>
  <input id="text2" type="text" />
</body>
</html>

Open in new window

0
 
LVL 3

Expert Comment

by:kingsob
ID: 24084364

<html>
<head>
</head>
<body>
  <input id="text1" type="text" onkeyup="document.getElementById('text2').value = this.value;" onmouseup="document.getElementById('text2').value = this.value;" oninput="document.getElementById('text2').value = this.value;" onpaste="document.getElementById('text2').value = window.clipboardData.getData('Text');"/>
  <input id="text2" type="text" />
</body>
</html>

Open in new window

0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 24084414
In case anyone is wonderting what oninput is

http://blog.amodernfable.com/2006/07/
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question