0

I have a form with inputs (each with ID param,param1,param3 respectively) and an external php file with a function called getform() that takes three parameters from the form (param, param1, param3 respectively).

A text feild with id results to display the response from php file.
I have placed onclick function on param3.

I need whenever a user types something in param3 it should be sent to php file and the results displayed in the text filed of id results.

here is my code

<script>
  function post(){
    var param = $('#param').val();
    var param2 = $('#param2').val();
    var param3 = $('#param3').val();
    $.post('curencyconvert.php', {
      postparam: param,
      postparam2: param2,
      postparam3:param3
    }, function(data){
      $('#results').html(data);
    });
  }
</script>

my php function in the php file

function Conv($param,$param2,$param3){
    //my code here
    return $output;
}
3
  • 1
    $_POST is where you'll find your postparam and postparam2 etc Commented Dec 23, 2016 at 10:18
  • the problem am not geting any respose form my php file. it seem like the javascript is not working. not even sending any thing. i have checked with javascrit alert(). but find no data sent to the php Commented Dec 23, 2016 at 10:25
  • You should try ajax, as described by @Faiz99 or even by @M A SIDDIQUI, In your case when did you call method Conv? It will not get called automatically Commented Dec 23, 2016 at 11:32

4 Answers 4

1
if(isset($_POST)){
//Calling the defined function here
Conv($_POST['postparam'], $_POST['postparam2'], $_POST['postparam3']);
}

Add these line below your function code.. and better echo the output in your function instead of returning it.

Sign up to request clarification or add additional context in comments.

2 Comments

the problem am not geting any respose form my php file. it seem like the javascript is not working. not even sending any thing. i have checked with javascrit alert(). but find no data sent to the php
Where are calling the post function...??
0

jQuery(document).ready(function($) {
$('#param3').change(function() {
// put here the code //
} );
})

1 Comment

you can use it to control the change of text in the #param3 , next you should add your code to put it in a hidden text box and submit the text box value to php file
0

What errors you get in Console(firbug)?

As stated by other answers $_POST should be used.

What your php code returns if it returns an array or returns an object It can not be put into the Input. Return value must be a string

PHP code must be :

      function Conv($param,$param2,$param3){
        //my code here
          // take particular field of the DB results or resultset that you want to show in the input.
            return $output['name'];

        }

I know answer is incomplete because your question is incomplete. Please let me know errors from the console so that i can help you further

Comments

0

echo instead of return.

if(isset($_POST)){
  echo Conv($_POST['postparam'], $_POST['postparam2'], $_POST['postparam3']);
}

Do something like this, it is more clean:

Conv($param, $param2, $param3){
   // your code here
   return $output;
}

As for the javascript part, jquery ajax is your friend

 function post(){

    var param = $('#param').val();
    var param2 = $('#param2').val();
    var param3 = $('#param3').val();

    $.ajax({
        url: '/path/to/file',
        type: 'POST',
        data : { postparam: param, postparam2: param2, postparam3: param3 },     
    }).done(function(data) {
          $('#results').html(data);
    });

}

Comments

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.