2

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 ?

Krish R
  • 22,583
  • 7
  • 50
  • 59
Harshana
  • 185
  • 3
  • 4
  • 12

3 Answers3

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 );
  });
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