Jump to content

Output to textbox from within a function


Muggins

Recommended Posts

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; ?>" />
 

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); ?>" />

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

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.

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];

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.