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 ?

3
  • Use ajax, or just submit the form. THat is after all what fors are for Commented Dec 25, 2013 at 8:13
  • 2
    POST the data, either Jquery or HTTP Commented Dec 25, 2013 at 8:14
  • For assigning js variable to php you can refer here stackoverflow.com/questions/12978927/… Commented Dec 25, 2013 at 8:21

3 Answers 3

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
Sign up to request clarification or add additional context in comments.

1 Comment

Ar you sure that $getthevalueofid = var id; works ?
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 );
  });

Comments

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
?>

1 Comment

how var id could work in php

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.