开发者

How to use jQuery to make an input's changing value a php variable?

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 r开发者_如何学Pythoneference:

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜