Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing in form field value to PHP file

Tags:

html

jquery

php

I'd like to do a dynamic search function using jQuery and PHP. I'm struggling passing the HTML form field to the JQUERY function (which would then get passed to the PHP file).

My major questions are:

1) How do I pass form "Input" field into Jquery function?

2) How do I get the PHP result in the form "Output" field?

I currently have... (simplified)

JQUERY:
$.get("SEARCH.php", {"_input" :  $('input[name=input]').val()},
function(returned_data) 
{
   $("input[name=output]").val(returned_data);
}


SEARCH.php:
$input = 'Welcome ' . $_GET['_input'];
echo $input;
//should be "Welcome" plus whatever I type in to "input"



HTML FORM:
input: <input type="text" name="input" value="" /> 
output: <input type="text" name="output" id="output" />         

Thank you!

like image 369
user3871 Avatar asked Nov 22 '25 03:11

user3871


2 Answers

jQuery

$.get("SEARCH.php", {"_input" : $('input[name=input]').val() },
function(returned_data) {
   $("input[name=output]").val( returned_data );
}

HTML

input: <input type="text" name="input" value="" />
output: <input type="text" name="output" />

PHP Use echo instead of return since it looks that your code isn't in function:

$input = $_GET['_input'];
do some parsing of the input
echo $result;
like image 111
Zoltan Toth Avatar answered Nov 24 '25 20:11

Zoltan Toth


jQuery

$.get("SEARCH.php", {"_input" : $('input[name=input]').val() },
function(returned_data) {
    $('#output').val(returned_data);
});

PHP

$input = $_GET['_input'];
do some parsing of the input
echo $result; // not return

HTML

input: <input type="text" name="input" value="" />
output: <input type="text" name="result" id="output" value="" />
like image 32
thecodeparadox Avatar answered Nov 24 '25 18:11

thecodeparadox



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!