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 ?
3
-
Use ajax, or just submit the form. THat is after all what fors are forJelle Ferwerda– Jelle Ferwerda2013-12-25 08:13:15 +00:00Commented Dec 25, 2013 at 8:13
-
2POST the data, either Jquery or HTTPScary Wombat– Scary Wombat2013-12-25 08:14:07 +00:00Commented Dec 25, 2013 at 8:14
-
For assigning js variable to php you can refer here stackoverflow.com/questions/12978927/…Hüseyin BABAL– Hüseyin BABAL2013-12-25 08:21:31 +00:00Commented Dec 25, 2013 at 8:21
Add a comment
|
3 Answers
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
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 );
});
Comments
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
?>
1 Comment
Amr
how var id could work in php