0

Here's my JS code...

function da(){
    var a=document.forms["user"]["age"].value;
    if(this.age.value < 18 || this.age.value > 85) {
        alert('some text...');
        this.age.focus();
        return false;
    }else{
        window.location.href='file.php?&'+a;
    }
}

It simply passes the parameters to the page where I'm standing... Here's the form just in case (I'm a beginner keep in mind)...

<form name="buscar" method="GET"> Some text <input                 onmouseover="Aj2('d');document.getElementById('box').style.display='block';" onmouseout="clean();" type="number" name="age" id="age" > Age <div id="help" ><!-- --> </div><br />
<input type="button" value="Send" onclick="da()">
</form>

The Aj2 function is not the problem here... Thanks for any help y might get...

Rob
  • 415,655
  • 72
  • 787
  • 1,044
Lucas
  • 9,871
  • 5
  • 42
  • 52
  • Use [ajax](http://api.jquery.com/jQuery.ajax/) for this. – Peon Feb 01 '13 at 16:02
  • 1
    the magic word.... **AJAX** now google. – itachi Feb 01 '13 at 16:02
  • possible duplicate of [Passing a JavaScript Value to a PHP Variable (With Limitation)](http://stackoverflow.com/questions/11029298/passing-a-javascript-value-to-a-php-variable-with-limitation) – Ja͢ck Feb 01 '13 at 16:18

2 Answers2

0

Some thing like this I am not a expert.

$('button name').on('click', function() {
   var age_ = document.getElemenetById('age');
   $.get('path of your file', {'age' : age_}, function(resp) {
        // code to pass parameter
        alert(age_);
   });
});
Ya Fa Su
  • 160
  • 1
  • 4
  • 13
0

Just a thought, if you don't actually have to reload the page and just want to get information to your javascript code from PHP, you could do something like

<script>

<?
    $phpvariable = "my variable";
?>

var jsvariable = <?php echo json_encode($phpvariable); ?>;

</script>

Now the javascript variable, jsvariable, will hold the PHP variable's content.

user1104854
  • 2,137
  • 12
  • 51
  • 74