Jump to content

Output to textbox from within a function


Muggins
Go to solution Solved by 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; ?>" />
 
Link to comment
Share on other sites

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 by PravinS
Link to comment
Share on other sites

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); ?>" />
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • Solution

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.