I have created a javascript for check the text boxes are empty. if one of text box is empty the return false. so how can i get that return value to a PHP variable ?
Asked
Active
Viewed 6.1k times
2
-
Use ajax, or just submit the form. THat is after all what fors are for – Jelle Ferwerda Dec 25 '13 at 08:13
-
2POST the data, either Jquery or HTTP – Scary Wombat Dec 25 '13 at 08:14
-
For assigning js variable to php you can refer here http://stackoverflow.com/questions/12978927/using-javascript-to-assign-a-php-variable – Hüseyin BABAL Dec 25 '13 at 08:21
3 Answers
3
If you are looking to assign return value in same page
<script language="javascript" >
var id = "data"
</script>
<?php
$getthevalueofid = var id;
?>
or use this line in submit button to posting the result to another page
result = your validation result
window.location.href="index.php?uid=result";
Call this in Another page to Get the return result
$somevar = $_GET["uid"]; //puts the uid varialbe into $somevar

Kirk
- 4,957
- 2
- 32
- 59
2
For linking javascript with php need to use AJAX http://api.jquery.com/jQuery.ajax/
$.ajax({
type: "POST",
url: "some.php",
data: { name: "John", location: "Boston" }
})
.done(function( msg ) {
alert( "Data Saved: " + msg );
});

Alexander.Shtanko
- 447
- 2
- 11
0
Do either form submit or url redirect with parameters, or ajax request to your php script and if your url query was ?foo=bar
, then in your PHP you can get it like this:
<?
$foo = $_REQUEST['foo']; // bar
?>

Lex Podgorny
- 2,598
- 1
- 23
- 40