Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Friends,

How can I update a multiple textboxes value with javascript, when user change the value of textboxes,
and I have a value already on those textboxes ?
JavaScript
<input type="text" id="amount_textbox"  önChange="UpdateValue()" value="100">
    <input type="text" id="amount_textbox"  önChange="UpdateValue()" value="200">
    
      function UpdateValue()
      {
   	//alert ("you have changed the textbox...");
        var x = document.getElementById('amount_textbox').value;
        document.getElementById("amount_textbox").setAttribute("value", x);
        document.getElementById('amount_textbox').value = x;		
      }

That function is working only for the first textbox,the second one can not update,how can I make other textbox worked ?

Thanks
Posted
Updated 8-Jan-12 20:13pm
v2

You can try this,
Both the ids are same ,
HTML
<input type="text" id="amount_textbox"  önChange="UpdateValue()" value="100">
<input type="text" id="amount_textbox"  önChange="UpdateValue()" value="200">

so change the id as 'amount_textbox1'
and then also, onChange =UpdateValue(this) in both code
JavaScript
function UpdateValue(t)
{
//alert ("you have changed the textbox...");
        							var x = document.getElementById(t).value;
document.getElementById(t).setAttribute("value", x);
document.getElementById(t).value = x;
}
}
 
Share this answer
 
v2
Comments
rider_1 4-Jan-12 0:04am    
Like this :
<input type="text" id="amount_textbox_0" önChange="UpdateValue(this)" value="100">
<input type="text" id="amount_textbox_1" önChange="UpdateValue1(this)" value="200">

function UpdateValue(t)

{
alert ("you have changed the textbox...");
var x = document.getElementById(t).value;
document.getElementById(t).setAttribute("value", x);
document.getElementById(t).value = x;

}

I tried at http://jsfiddle.net/N5RWn/1/
rider_1 4-Jan-12 0:06am    
it's not working ??
rider_1 4-Jan-12 0:23am    
error :
document.getElementById(t) is null
anushripatil 4-Jan-12 0:39am    
check with t.id or you can use
document.getelementbyid("amount_textbox_0")....&
document.getelementbyid("amount_textbox_1")...
try by changing the id of second textbox and pass one indicator to function.

HTML
<input type="text" id="amount_textbox1" önchange="UpdateValue(1)" value="100">
<input type="text" id="amount_textbox2" önchange="UpdateValue(2)" value="200"></input></input>

JavaScript
function UpdateValue(Ind)
{
        if (Ind==1)
{							
var x = document.getElementById('amount_textbox1').value;
document.getElementById("amount_textbox1").setAttribute("value", x);
document.getElementById('amount_textbox1').value = x;
}
else
{
var x = document.getElementById('amount_textbox2').value;
document.getElementById("amount_textbox2").setAttribute("value", x);
document.getElementById('amount_textbox2').value = x;

}
}


hope it works..
 
Share this answer
 
v2
Comments
rider_1 4-Jan-12 0:08am    
it doesn't work...
Karthik Harve 4-Jan-12 0:10am    
what is the problem or error..??
rider_1 4-Jan-12 0:24am    
If I have multiple ( dynamic ) textbox ? do you have ideas ?
rider_1 4-Jan-12 0:16am    
for( $i = 0; $i < count( $_POST['pay'] ); $i++)
{
echo '<input type="text" class="amount_text_change" id="amount_textbox" önChange="UpdateValue()" value="'.$amount_due.'">';
}

How can I do that ? so many ifs ??
rider_1 4-Jan-12 0:34am    
is it possible to do it in a loop ?
JavaScript
function get()
{
var text1=document .getElementById ("textbox1").value;
var text2=document .getElementById ("textbox2").value;
if(text1!="")

{
text2==text1;
return true
}
return false
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900