sfchun
05-04-2011, 04:23 PM
Hello ,
I'm having an issue when trying to change an input text value dynamically.
here is the picture :)
code :
the page is written in php generating some javascript...
purpose :
dynamically control an input, and following this input changing the state of an other one (that will determinate if the form can be submited).
info :
- UserInputID input is the one to be checked in real time
- validityID input is the one to be changed dynamically
- isShortNameKey(event) keydown, controls the input key and do not allow some specific caracters (it works fine).
- validateUserInput(event) , keyup event management, check the input result and check if already exists in database, then report it in targetDiv (it works fine).
problem :
After comparing the input with db, i would like to change the status of validityID input text.
If input already exists indatabase, validityID should be set to NO, else to YES.
php page
[...]
echo '<input type="text" id="validityID" name="validityNAME" value="NO" />';
echo "<input type=\"text\" size=\"8\" maxlength=\"8\" id=\"UserInputID\" name=\"UserInputName\" value=\"\" style=\"background-color:#ccffbb\" on
keypress=\"return isShortNameKey(event)\" onkeyup=\"validateUserInput(event)\" /></td>";
echo "<td><span id=\"targetDiv\"><i>Machine Type validity</i></span>";
[...]
if ($dbresult == $userinput) {
echo "<script type=\"text/javascript\">
setthisinputboxtextto('validityID','NO');
</script>";
echo '<span style="color:red">not ok, it already exists</span>';
} else {
echo "<script type=\"text/javascript\">
setthisinputboxtextto('validityID','YES');
</script>";
echo '<span style="color:green">ok it does not exists yet</span>';
}
setthisinputboxtextto function (Javascript)
function setthisinputboxtextto(inputboxid, valuetoset) {
if(!document.getElementById ) return; // Make sure browser supports getElementById
var inputObj = document.getElementById(inputboxid);
inputObj.value = valuetoset;
alert('inputboxid : '+inputboxid);
alert('valuetoset : '+valuetoset);
}
So ,
- the (php) test comparing database and input is always working fine
- but no alert comes up later in javascript ... and it never change the text content of validityID input box.
If anyone can see something evident, that i missed :(
Thanks for your help...
I'm having an issue when trying to change an input text value dynamically.
here is the picture :)
code :
the page is written in php generating some javascript...
purpose :
dynamically control an input, and following this input changing the state of an other one (that will determinate if the form can be submited).
info :
- UserInputID input is the one to be checked in real time
- validityID input is the one to be changed dynamically
- isShortNameKey(event) keydown, controls the input key and do not allow some specific caracters (it works fine).
- validateUserInput(event) , keyup event management, check the input result and check if already exists in database, then report it in targetDiv (it works fine).
problem :
After comparing the input with db, i would like to change the status of validityID input text.
If input already exists indatabase, validityID should be set to NO, else to YES.
php page
[...]
echo '<input type="text" id="validityID" name="validityNAME" value="NO" />';
echo "<input type=\"text\" size=\"8\" maxlength=\"8\" id=\"UserInputID\" name=\"UserInputName\" value=\"\" style=\"background-color:#ccffbb\" on
keypress=\"return isShortNameKey(event)\" onkeyup=\"validateUserInput(event)\" /></td>";
echo "<td><span id=\"targetDiv\"><i>Machine Type validity</i></span>";
[...]
if ($dbresult == $userinput) {
echo "<script type=\"text/javascript\">
setthisinputboxtextto('validityID','NO');
</script>";
echo '<span style="color:red">not ok, it already exists</span>';
} else {
echo "<script type=\"text/javascript\">
setthisinputboxtextto('validityID','YES');
</script>";
echo '<span style="color:green">ok it does not exists yet</span>';
}
setthisinputboxtextto function (Javascript)
function setthisinputboxtextto(inputboxid, valuetoset) {
if(!document.getElementById ) return; // Make sure browser supports getElementById
var inputObj = document.getElementById(inputboxid);
inputObj.value = valuetoset;
alert('inputboxid : '+inputboxid);
alert('valuetoset : '+valuetoset);
}
So ,
- the (php) test comparing database and input is always working fine
- but no alert comes up later in javascript ... and it never change the text content of validityID input box.
If anyone can see something evident, that i missed :(
Thanks for your help...