<?php
if ( isset ($_POST['source']) )
{
$source=$_POST['source'];
}
else
{
$source=0;
}
?>
<form method="post">
<input type="text" name="[COLOR="Blue"]source[/COLOR]" value="<?php echo $source ?>">
<input type="text" name="copy" value="<?php echo $source ?>">
<input type="submit">
</form>
I have the code above,
If I enter “someText” in the input box “source” and click the submit button,
“someText” will be seen the input box “copy”.
I like to make it like the following.
If I enter “someText” in the input box “source”,
“someText” will be simultaneously seen the input box “copy” without clicking the submit button.
First of all, i recomend you no to use <input type=“submit”> it’s better to use <input type=“button”> to get more control of what you want to do.
For copying text you can use a code like this one
var oDest = new Object;
function setCopyEvent()
{
try {
var o = document.getElementById("source");
o.onkeyup=copyTxt;
oDest = document.getElementById("copy");
}catch(anye){
//catching the error
}
}
function copyTxt(e)
{
try {
if (!e)
{ //ie browser
var e = window.event;
var o = e.srcElement;
}else{ //gecko
var o = e.currentTarget;
}
oDest.value=o.value;
}catch(anye){
//error here
}
}
Call the “setCopyEvent()” function on load, it is not tested, but it should work fine.
See you
Or if you want to keep things simple, you can just use this after the form. Preferably, at the end of the body, just before the </body> tag.
var source = document.getElementsByName('source')[0];
source.onkeyup = function () {
var copy = this.form.elements.copy;
copy.value = this.value;
}
Thank you, pablogo and paul.
They work fine.
Can I call it ajax?
It is not asynchronous and it doesn’t send or receive information to a remote server, so no. You would be very wrong to call it ajax.
Thank you for making me getting the concept by your kind explanation.