Response title
This is preview!
The following code is successfully passing the variable ‘x’ to PHP, but this is done outside JavaScript:
Please anyone can help me with an idea, using my code or Jquery, to pass inside JavaScript the value of 'x' into $what_is_myVar
Thanks for any reply,
I followed your recommendation, the following code works fine, the function load()
sends the selected radio button info to the PHP page and display the returned:
<head>
<script>
$(document).ready(function(){
$('#myButtons input:radio').change(function() {
var buttonValue = $("#myButtons input:radio:checked").val();
$("#myDiv").load('myPHPfile.php', {selectedButtonValue : buttonValue});
});
});
</script>
</head>
<body>
<div id="myButtons">
<input type="radio" name="category" value="10" />ButtonA
<input type="radio" name="category" value="20" />ButtonB
<input type="radio" name="category" value="30" />ButtonC
</div>
<div id="myDiv">Click the button to load results</div>
</body>
myPHPfile.php
<?php
if( $_REQUEST["selectedButtonValue"] )
{
$buttonPHP = $_REQUEST['selectedButtonValue'];
echo "Value button is ". $buttonPHP;
}
?>
I need an alert box message of the returned PHP value, inside the script, as follows:
;
$("#myDiv").load('myPHPfile.php', {selectedButtonValue : buttonValue});
alert('<?php echo $buttonPHP ?>');
;
Would it be possible to write the PHP value inside JavaScript (maybe by using '$get()' instead 'load()' )?
© 2013 jQuery Foundation
Sponsored by and others.