Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

Community Beginner ,
Oct 10, 2012 Oct 10, 2012

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

TOPICS
Server side applications
348
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 11, 2012 Oct 11, 2012
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines