0

Is it possible using jQuery, or any other language, to make an input's value a php variable without saving or refreshing the page?

I am trying to build a simple math form that has one constant and one variable. I need the calculated value to be displayed similar to the Live Preview with jQuery script.

<input type="text" name="word" value="<?php $second_number ?>" />
<?php 
$first_number = 10;
$sum_total = $first_number + $second_number;
print ($sum_total); ?>

Live Preview with jQuery snippet, for reference:

<script type="text/javascript">
$(function() 
{
$(".word").keyup(function() 
{
var word=$(this).val();
$(".word_preview").html(word);
return false;
});
});
</script>

1 Answer 1

1

No, it's not.

PHP is a pre-processor: its output is the HTML and Javascript that runs on your web browser. The PHP logic has long gone by the time it reaches the browser.

If you want to provide data to a PHP script and get data back out of it (for use on the web), you must do this through an HTTP request.

Make it an inline one (XmlHttpRequest or "AJAX") if you wish.

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

1 Comment

Thanks! I'll redirect my search for a jQuery math plugin and also look into an AJAX request...

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.