hlstriker Posted September 21, 2008 Share Posted September 21, 2008 I'm trying to update a textbox value with php but it's just giving errors. Here is the code I'm using: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <title>Form test</title> <script language="JavaScript"> function UpdateTextBox(percent) { document.getElementById("test").value = percent; } </script> </head> <body> <form> <input type="text" id="test" name="test" value="Null" onclick="UpdateTextBox('Testing')" /> </form> </body> </html> <?php for($i=0;$i<9999;$i++) { // Update textbox with value $i UpdateTextBox('$i'); } ?> The error is: Fatal error: Call to undefined function updatetextbox() in C:\xampp\htdocs\formtest.php on line 27 Does anyone know how to fix this? Quote Link to comment https://forums.phpfreaks.com/topic/125221-solved-update-textbox-value-with-php/ Share on other sites More sharing options...
.josh Posted September 21, 2008 Share Posted September 21, 2008 that's not php that's javascript. edit: And that error means that javascript can't find the function. As in, it's not in the file somewhere. Quote Link to comment https://forums.phpfreaks.com/topic/125221-solved-update-textbox-value-with-php/#findComment-647270 Share on other sites More sharing options...
hlstriker Posted September 21, 2008 Author Share Posted September 21, 2008 Is there a way to change the textbox value using only php? If not how could I make the value change in my php loop? Quote Link to comment https://forums.phpfreaks.com/topic/125221-solved-update-textbox-value-with-php/#findComment-647292 Share on other sites More sharing options...
.josh Posted September 22, 2008 Share Posted September 22, 2008 Well, yes. You can have a form where you enter in the value, and click a submit button, and use php to populate the textbox with that data, but that's not really "real time." Suppose it depends on what your goals are. If you want something "real time," then you need to stick with javascript, because php is parsed on the server. Quote Link to comment https://forums.phpfreaks.com/topic/125221-solved-update-textbox-value-with-php/#findComment-647336 Share on other sites More sharing options...
CroNiX Posted September 22, 2008 Share Posted September 22, 2008 The problem is in your very last lines of code. You are trying to execute a javascript function within php. <?php for($i=0;$i<9999;$i++) { // Update textbox with value $i ?> <script language="javascript">UpdateTextBox('<?php echo $i; ?>')</script> <?php } ?> No clue why you're trying to do it like this, but this should make it work....all 9999 times LOL Quote Link to comment https://forums.phpfreaks.com/topic/125221-solved-update-textbox-value-with-php/#findComment-647515 Share on other sites More sharing options...
.josh Posted September 22, 2008 Share Posted September 22, 2008 no...javascript does not get executed on the server. You cannot put javascript inside a php loop and expect the javascript to be run. That's not how it works. Did you read the error he posted? Fatal error: Call to undefined function updatetextbox() in C:\xampp\htdocs\formtest.php on line 27 It means javascript got to the line of code where it's calling updatetexbox and it can't find it. Quote Link to comment https://forums.phpfreaks.com/topic/125221-solved-update-textbox-value-with-php/#findComment-647648 Share on other sites More sharing options...
hlstriker Posted September 22, 2008 Author Share Posted September 22, 2008 CroNiXs code actually works because it's writing a new javascript line as the loop is going. I only wanted to loop 9999 times to see if I could watch the textbox get updated in real time. The result was the textbox updating but so many javascript lines were being executed that the textbox number was lagging behind and sometimes locked the browser up. Thanks for the help everyone. Quote Link to comment https://forums.phpfreaks.com/topic/125221-solved-update-textbox-value-with-php/#findComment-647679 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.