0

Hello, I have an input field named result. I want to call a function when something changes in this input. I tried this :

<input onchange="maFonction" id="result" readonly="readonly" type="text" value="0" size = "10" /> 

And tried to call this function

<?php
function maFonction()
{

$a = 40 ;
if ($result > $a) {

     echo "trop dheure";
     } elseif ($result == $a) {
     ?>
                    <input onclick="s(this.form);" type="button" value="sauvegarder" /> 
        <?php
        } else {
    echo "moins de 40 heures a été effecuté";
}


}
?>

What mistake did I do or what am I missing?

15
  • 1
    Try something like onchange="maFonction()" using () for a function. Commented Apr 7, 2014 at 17:23
  • 2
    You can not call a PHP function directly using DOM events. Where is the AJAX call? How does it look like? Commented Apr 7, 2014 at 17:24
  • nothing change no message appear. and no error on console Commented Apr 7, 2014 at 17:25
  • I don'T have ajax for the moment I know ajax can make it but I don't know how to used it. Commented Apr 7, 2014 at 17:25
  • php already ends work... there is no any php function... Commented Apr 7, 2014 at 17:27

2 Answers 2

1

If you realy want to use PHP, call a php file instead a function.

Your form

<form method="post" action="myfunc.php">
    <input type="text" name="myname">
    <input type="submit" value="click" name="submit">
</form>

Your php file: myfunc.php

<?php
function display()
{
    echo "hello ".$_POST["myname"];
}
if(isset($_POST['submit']))
{
   display();
} 
?>
Sign up to request clarification or add additional context in comments.

2 Comments

this is not a button this is a input i cannot click . i really need if the number in the input change a message appear.
it's the idea to know how to call a function() with a form. From here on you know what and how to do...
0
<input onchange="maFonction()" id="result" readonly="readonly" type="text" value="0" size = "10" /> 

javascript

maFonction = function(){
$.post("yourFile.php");
}

and your php

<?php

$a = 40 ;
if ($result > $a) {

     echo "trop dheure";
     } elseif ($result == $a) {
     ?>
                    <input onclick="s(this.form);" type="button" value="sauvegarder" /> 
        <?php
        } else {
    echo "moins de 40 heures a été effecuté";
}


}

?>

6 Comments

why do you make this request? where you use its result?
I just call his php function from html using javascript
the message won't change when the input number change
How can the input number change when it can't be changed in the first place? readonly="readonly" @TheBaconManWithouBacon
I have 8 input. 7 to calcul for each day in one week and the last one is the result. If sunday i writes 8 hours , monday 5 hours .. and all of the 7 input is additionated and transfer into the result input. So i already use ajax for calculate the result when i change one of the day number is recalculate automaticly the result exemple : sunday 5, monday 5, tuesday 5, thurday 5, wenesday 5, friday 5, saturday 5 = 25 in the result. if I change monday for 4 in my result they recalculate and show 24. so I want when the number change a msg appear if under 40 superior of 40
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.