Muggins Posted March 8, 2014 Share Posted March 8, 2014 Hi How do I output to a textbox from within a function: I know I can call the function and send a response from it to the textbox but the function is complex and sends to 10 boxes. thanks <?php $response = "hello"; function test() { $response = "hello"; } ?> <html> <input type="textbox" name="xx" value="<?php echo $message; ?>" /> Quote Link to comment Share on other sites More sharing options...
PravinS Posted March 8, 2014 Share Posted March 8, 2014 (edited) your function should return the value like <?php function test() { $response = "hello"; return $response; } ?> and then you can call the function like this <input type="textbox" name="xx" value="<?php echo test(); ?>" /> Edited March 8, 2014 by PravinS Quote Link to comment Share on other sites More sharing options...
Muggins Posted March 8, 2014 Author Share Posted March 8, 2014 Hi PravinS Thanks for that but the function is returning 10 different responses to 10 textboxes. John Quote Link to comment Share on other sites More sharing options...
davidannis Posted March 8, 2014 Share Posted March 8, 2014 Then try: <?php function test($textboxnumber) { switch ($textboxnumber) { case 1: $response = "hello"; break; case2: $response= "goodbye"; break; .... case 10: $response = 'response 10'; break; default: $response="oops, I don't know hat to say"; break; } return $response; } ?> and call your function with the texbox number. <input type="textbox" name="xx" value="<?php $textboxnumber=2 ; echo test($textboxnumber); ?>" /> Quote Link to comment Share on other sites More sharing options...
Muggins Posted March 8, 2014 Author Share Posted March 8, 2014 Again thanks for the response but, the function that I'm using is parsing a long TCP response from a server and pulling out various bits of information. I only want to run it once. I'm new to PHP, maybe a function can return an array that I can use to populate the boxes. John Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted March 8, 2014 Share Posted March 8, 2014 sorry, but you cannot sneak up on a problem in programming (programming is like a vague/sneaky-person detector.) you must fully define what the inputs are, what processing you are going to do for those inputs, and what result you are trying to produce. based on the information you have posted, the replies you have gotten are all that anyone can tell you. if you want a programming forum to help with your problem, you must communicate - what a sample of the input data is, what processing you are going to do for those inputs, and what result you are trying to produce. Quote Link to comment Share on other sites More sharing options...
Solution Muggins Posted March 8, 2014 Author Solution Share Posted March 8, 2014 Apologies but I'm not accustomed to posting on forums. My initial post was a feeler to see if there was a simple answer to a simple question ie Can you populate a textbox from within a function. I didn't want to complicate the post by reference to TCP sockets, parsing etc. Anyway thanks got an answer function getXYZ(){return array(1,2,3);}$array = getXYZ();$x = $array[1];$y = $array[2];$z = $array[3]; Quote Link to comment 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.