A Call to PHP Function on INPUT field is not working

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Easytime
    New Member
    • Nov 2012
    • 26

    #1

    A Call to PHP Function on INPUT field is not working

    Dear Pros,

    I've written a php function script to check the a default value of a text field during an onFocus and onMouseOut events.
    The default value of the text field is 'Search'.
    When a user sets focus on the text field, the value should clear to empty string.
    When the user removes focus and without entering a text, the value should be set back to 'Search'.
    Else a $value variable should be assigned the value of the user input in the text field.
    Please see the code below and help me out - cos, I am having problem calling the script on the input field. I'm not even sure whether the script is wrong or not...

    Code:
    <?php
    function setValue()
       {
    if (!empty($_REQUEST['qfront']) && $_REQUEST['qfront']=='Search')
       {
     
     $value=''; //$_REQUEST['qfront']="";
       }
       elseif (!empty($_REQUEST['qfront']) && $_REQUEST['qfront']!='Search')
       {
     $value=$_REQUEST['qfront'];
        }
       else //if (empty($_REQUEST['qfront'])
       {
    $value='Search';
       }
    return setValue();
    }
    ?>
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    PHP is a server side language. It will not run on the client's computer. What you want to do is run something when the client takes a certain action, to do that, you need to use a client side language like Javascript.

    Comment

    • Easytime
      New Member
      • Nov 2012
      • 26

      #3
      I have a WAMP installed on my computer. I use PHP to script other functions and they run. I develop my files on php and they run just because I have installed WAMP on my pc. It;s just that, I'm having problem figuring out where the code has a bug that does not allow it to run.

      Pls kindly help me.
      Thank you!

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        I didn't say PHP wouldn't run. But it will only run on your server. If you are trying to do something on the client's computer however, you will need to use a client side script like Javascript. onFocus and onMouseout events are client side events. Hence you need to use client side scripting. Like Javascript.

        Comment

        Working...