admin管理员组文章数量:1315355
First of all.. is this possible? I work&create a var in javascript (jquery ui framework) and then when I click on the "Submit" button of my form it should this variable?
HTML & Javascript (Jquery UI):
<script>
$(document).ready(function() {
var slider1 = $( "#slider1" ).slider( "value" );
var slider2 = $( "#slider2" ).slider( "value" );
});
</script>
pseudo: HTML & PHP:
<?php echo slider1 ?>
How can I echo the value of #slider1 ??
First of all.. is this possible? I work&create a var in javascript (jquery ui framework) and then when I click on the "Submit" button of my form it should this variable?
HTML & Javascript (Jquery UI):
<script>
$(document).ready(function() {
var slider1 = $( "#slider1" ).slider( "value" );
var slider2 = $( "#slider2" ).slider( "value" );
});
</script>
pseudo: HTML & PHP:
<?php echo slider1 ?>
How can I echo the value of #slider1 ??
Share Improve this question edited Jan 25, 2011 at 8:23 Dan Grossman 52.4k10 gold badges115 silver badges101 bronze badges asked Jan 25, 2011 at 8:19 TomkayTomkay 5,16021 gold badges65 silver badges94 bronze badges 2- What is #slider1? Is that some kind of input in a form? – Dan Grossman Commented Jan 25, 2011 at 8:23
- 1 You could create a hidden input field that holds the 'slider1' variable for example. Everytime the slider1 value is updated you should also update the hidden input field. Then, after submitting the hidden variable will be available in PHP. – dvk Commented Jan 25, 2011 at 8:24
4 Answers
Reset to default 5You cannot assign a variable from javascript to php, but you can set a javascript variable to a form input element before you send the form, then you can get the values via the $_POST or $_GET (or the $_REQUEST) superglobal arrays, based on your method ().
http://php/manual/en/reserved.variables.get.php
http://php/manual/en/reserved.variables.post.php
For example:
Javascript:
$(document).ready(function(){
var test = "test";
$('#someinput').value(test);
});
Html:
<form action="some.php" method="post">
<input type="hidden" id="someinput" name="someinput"/>
<input type="submit" value="send"/>
</form>
PHP:
<?php
var_dump($_POST['someinput']);
?>
Mike you cannot mix server side code with client side code. They are pletely seperate!
What you can do is just before the form posts put some value inside a hidden input and check it on the server side
add it to hidden input in your form
like
$('#hidden_field').val(slider1)
You are misunderstanding how PHP and Javascript work. PHP runs on the server, JavaScript runs on the browser. When JavaScript runs, PHP is already done generating the document.
If you have a JavaScript variable, you need to use JavaScript to alter the element.
For example:
<div id="slider_value"></div>
<script>
$(document).ready(function() {
var slider1 = $( "#slider1" ).slider( "value" );
var slider2 = $( "#slider2" ).slider( "value" );
// Assign value to DIV
$("#slider_value").html("Value: "+slider1);
});
</script>
本文标签: JQuery (UI) Javascript Variable convert to PHP VariableStack Overflow
版权声明:本文标题:JQuery (UI): Javascript Variable convert to PHP Variable - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741975734a2408109.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论