Using AJAX or jQuery in WordPress to Return Results of PHP Script -


i have html form accepts user input:

<form action="script_conv.php" method="post"> convert: <input type="number" name="input" id="input"> <select name="unit1" id="unit1"> <option value="w">words</option> <option value="l">lines</option> <option value="p">pages</option> <option value="r">recorded minutes</option> <option value="f">finished minutes</option> </select> <select name="unit2" id="unit2"> <option value="w">words</option> <option value="l">lines</option> <option value="p">pages</option> <option value="r">recorded minutes</option> <option value="f">finished minutes</option> </select> <input type="submit"> </form> 

the php script takes user data , performs calculations:

<?php $input=$_post["input"]; $unit1=$_post["unit1"]; $unit2=$_post["unit2"];  (bunch of if...else statements)  echo "<ul>"; echo "<li>$cat1f</li>"; echo "<li>$cat2f</li>"; echo "<li>$cat3f</li>"; echo "</ul>"; ?> 

this works fine, of course results of function returned new page. i'd append results of function same page. know require ajax/jquery, nothing i've tried has worked. can give me guidance?

much appreciated!

try test.php(html):-

<form method='post'> convert: <input type="number" name="input" id="input"> <select name="unit1" id="unit1"> <option value="w">words</option> <option value="l">lines</option> <option value="p">pages</option> <option value="r">recorded minutes</option> <option value="f">finished minutes</option> </select> <select name="unit2" id="unit2"> <option value="w">words</option> <option value="l">lines</option> <option value="p">pages</option> <option value="r">recorded minutes</option> <option value="f">finished minutes</option> </select> <input type="button" onclick="getvalue();"> </form> 

test.php (script function):-

<script src="http://localhost:8004/js/jquery-1.9.1.js"></script> <script> function getvalue() {        var input= document.getelementbyid('input').value;     var unit1=document.getelementbyid('unit1').value;     var unit2=document.getelementbyid('unit2').value;          $.ajax({         type: "post",         url: "http://localhost:8004/test/test.php",         data: { input: input,unit1:unit1, unit2:unit2,fun:'getvalue' }         }).done(function( data )          {             alert(data);         });  }  </script> 

php code @ top of (test.php)file:-

<?php if(isset($_request['fun']) == 'getvalue')  { echo $_request['input'].$_request['unit1'].$_request['unit2']; exit(); } ?> 

you need exit else display data file use way using php doing in php

remove action <form method="post"> , response on same page


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -