0

i need to run the php with two different parameters, when mouse is down and when mouse is up. how can i do this?
thanks.

i have this HTML:

<script src="jquery.js"></script> 
      <script src="jquery.form.js"></script> 
      <script> 
         $(document).ready(function() { 
             $('#mbed').ajaxForm(function() {}); 
         }); 
      </script> 
   </head>
   <body>
      <form id="mbed" target="_blank" action="mbed.php" method="post">
         <input type="submit" name="increment" value="Faster">
         <input type="submit" name="decrement" value="slower">

and this file - mbed.php:

<?php
if(isset($_POST['increment'])) {
        $sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
        $msg = "FF0100";
        $len = strlen($msg);
        socket_sendto($sock, $msg, $len, 0 ,'192.168.1.199', 12345);
        socket_close($sock);
    }
if(isset($_POST['decrement'])) {
        $sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
        $msg = "FF0101";
        $len = strlen($msg);
        socket_sendto($sock, $msg, $len, 0 ,'192.168.1.199', 12345);
        socket_close($sock);
    }
?>
  • 3
    you can't. PHP is a serverside language. Use javascript, possibly ajax. Send the interaction results to the server. But sending ajax requests on mouseover/mouseout could create latency in the user experience, unless your frontend doesn't use the server's output response. – pixeline Sep 13 '14 at 08:30

1 Answers1

0

I think just can be by ajax

$("#mbed").mouseup(function(){
   $.ajax({url:"mousedown.html",tpye:"POST",data:"your data",success:successFunc()})
}).mousedown(function(){
 $.ajax({url:"mousedown.html",tpye:"POST",data:"your data",success:successFunc()})
})
budamivardi
  • 722
  • 5
  • 10
  • it not work. where i need to put it? what is mousedown.html? – or kats Sep 13 '14 at 11:26
  • OMG =) mousedown.html is your ajax page which you have to code it. You must write two differrent page or one page which have two different proccess are detected by a parameter from ajax. .mouseup() and mousedown() are jQuery methods, also ajax() Lool these, http://api.jquery.com/mousedown/ , http://api.jquery.com/jquery.ajax/ , http://api.jquery.com/mouseup/ – budamivardi Sep 13 '14 at 12:13
  • i am not so familier with this codes. please give example with more details. thank you very much. – or kats Sep 13 '14 at 15:29