Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

This question already has an answer here:

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 ?

share|improve this question

marked as duplicate by Quentin, Jürgen Thelen, BobTheBuilder, greg-449, Dhaval Marthak Dec 25 '13 at 9:53

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
Use ajax, or just submit the form. THat is after all what fors are for –  Jelle Ferwerda Dec 25 '13 at 8:13
2  
POST the data, either Jquery or HTTP –  Scary Wombat Dec 25 '13 at 8:14
    
For assigning js variable to php you can refer here stackoverflow.com/questions/12978927/… –  Hüseyin BABAL Dec 25 '13 at 8:21

3 Answers 3

up vote 1 down vote accepted

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 );
  });
share|improve this answer

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
?>
share|improve this answer

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
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.