Oranje
Oranje

Reputation: 67

How to get the value from Javascript Prompt Box and Pass it into PHP variable to be able to save in SQL?

Here is my problem, I want my script to do this: -before the user reject entry(server side), system must prompt text box asking the reason why they want to reject it. and then save the reason they input to MySQL server.

Javascript Function:

function MyReason(){
    var reason = prompt("Reason");
}

PHP Snippet:

echo "<td> <a href=changeStatReject.php?id=" . $row['id'] . ">"  . "<img src='media/reject.png'>" . "</a></td>";

From Here, I want to get the value of prompt box and pass it to

changeStatReject.php

and save it in DB.

Thanks Mates.

Upvotes: 1

Views: 9453

Answers (2)

manassorn
manassorn

Reputation: 450

You can send value to hidden input in the form and submit it.

function MyReason(){
    var reason = prompt("Reason");
    document.getElementById("reason").value = reason;
    document.getElementById("form").submit();
}

<form id="form">
    <input type="hidden" id="reason" />
</form>

Upvotes: 3

Farrokh
Farrokh

Reputation: 1167

try this code:

function MyReason(){
    var reason =  prompt("Reason");
    document.getElementById('hiddenNameField').value = reason;
    document.forms(0).submit();
}

Upvotes: 0

Related Questions