Thursday, June 6, 2024
 Popular · Latest · Hot · Upcoming
117
rated 0 times [  123] [ 6]  / answers: 1 / hits: 51015  / 7 Years ago, mon, may 22, 2017, 12:00:00

In javascript i want to know how to send data to php file using post method.
I have tried diffewrent method. But i didn't get any output so please help me.
My code is shown below.



index.php



<form method=post name=form enctype=multipart/form-data>
<input type=text name=name id=name placeholder=Name required/>
<input type=email name=email id=email placeholder=Email required/>
<input type=password name=pass id=pass placeholder=Password required/>
<input type=submit name=submit value=Send onclick=myFunction()/>
</form>

<script>
function myFunction() {
var name = document.getElementById(name).value;
var email = document.getElementById(email).value;
var password = document.getElementById(password).value;
//// I want post the values to profile.php
}
</script>


profile.php



if (isset($_POST['submit'])) {
$name = $_POST['name'];
}

More From » php

 Answers
12

Do something like this and pass your values like this and you can check in your profile.php page....Here you cannot check if(isset($_POST['submit'])), but you you can check if(isset($_POST['name']))


    <form method="post" name="form" enctype="multipart/form-data">
<input type="text" name="name" id="name" placeholder="Name" required/>
<input type="email" name="email" id="email" placeholder="Email" required/>
<input type="password" name="pass" id="pass" placeholder="Password" required/>
<input type="submit" name="submit" value="Send" onclick="myFunction()"/>
</form>

<script>
function myFunction() {
var name = document.getElementById("name").value;
var email = document.getElementById("email").value;
var password = document.getElementById("password").value;
$.ajax({
type : "POST", //type of method
url : "profile.php", //your page
data : { name : name, email : email, password : password },// passing the values
success: function(res){
//do what you want here...
}
});
}
</script>

[#57709] Thursday, May 18, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mariselas

Total Points: 711
Total Questions: 117
Total Answers: 110

Location: Burkina Faso
Member since Thu, Dec 23, 2021
3 Years ago
;