1

my javascript processes my form and redirects me but it does not post the input values in the php file it redirects to

my javascript processes my form and redirects me but it does not post the input values in the php file it redirects to

<script type="text/javascript">  
function jumper(){  
    var number=document.getElementById("email").value; 
    var idx ="";
    var idz="";
if (idx > -1 ) {
  document.location.href = '/run.php' ;
}
else if(idz > -1 ) {
  document.location.href = 'https://stackoverflow.com/questions/40539097/redirect-user-to-another-html-page-if-the-condition-is-true' ;
}
else{
    alert("sorry");
}
} 
</script>

i expect that javascript not just redirect but it shoudl also post input values to email from php file

2 Answers2

0

I would suggest looking at https://api.jquery.com/jquery.post/

Right now, you're 'directing' in a GET or normal fashion, without carrying any data from page, to page.

Using jQuery POST function, you'll be able to stay on the same page, and submit your data to the external PHP page (on the same server of course), and receive a result which can be displayed whether it's successful or has failed.

There will be a bit to learn and read on this subject, but I guarantee it will be worth it.

Some key words:

AJAX (what you should be using), PHP (backend), JSON (language to communicate the form values, and also result from the backend).

Hope this helps,

Kind regards,

Gareth
  • 92
  • 8
0

When you assign new location in the location history It is the same as clicking a link. You are supposed to submit the form using javascript traditionally and not by just assigning a new location.

var form = document.getElementsByTagName("form")[0];
form.action = "/run.php";
form.method = "post";

form.submit();

Now the code above should post the form and redirect you to the required php file.

James
  • 120
  • 1
  • 7