最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin2浏览0评论

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.

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.

Share Improve this question edited Aug 19, 2014 at 5:47 Husen 9351 gold badge6 silver badges18 bronze badges asked Aug 19, 2014 at 5:40 OranjeOranje 671 silver badge9 bronze badges 3
  • There're 2 options. Use ajax or submit form. – manassorn Commented Aug 19, 2014 at 5:43
  • how can I use submit in this @manassorn – Oranje Commented Aug 19, 2014 at 5:48
  • I'd remend you go for the jQuery-library to make Ajax easier. Take a look at this really simple and basic tutorial: [Link]ajaxtutorial/index.php/2010/03/03/… – Atanu Commented Aug 19, 2014 at 5:58
Add a ment  | 

2 Answers 2

Reset to default 3

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>

try this code:

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

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论