Skip to main content
Participant
October 10, 2012
Question

How to post a value to a field from a function?

  • October 10, 2012
  • 1 reply
  • 348 views

Hi all. I have created a function that checks two values to see if they match. If they do then just return otherwise I want a text field to display a message saying that the totals do not match. How do I update the text field value from the function?

The function:

function compare_values($TotOrdered, $TotCount)

{

    If ($TotOrdered  != $TotCount)

    {

        return "Does not match";

    }

    else

    {

        return;

    }   

}

I call it like this:

$Message1 = compare_values(number_ordered, total);

I tried this:

<input name="message1" type="text" id="message1" value=""'.$Message1' />

but no joy...

I keep thinking I need a POST command here but not sure...

Help!

Thanks in advance.

Robert

This topic has been closed for replies.

1 reply

David_Powers
Inspiring
October 11, 2012

To display the value you need to embed it in a PHP block and use echo:

<input name="message1" type="text" id="message1" value="<?php echo $Message1; ?>" />

You will also need to reload the page, because PHP is a server-side language. Your function will work only when the form is submitted.