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 ec开发者_如何转开发ho slider1 ?>
How can I echo the value of #slider1 ??
You 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.net/manual/en/reserved.variables.get.php
http://php.net/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 completely 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>
精彩评论