JS prompt into PHP variable

Associate
Joined
4 Feb 2014
Posts
12
I have a JS prompt windows that appears within certain IF statement in PHP and I want the message typed in by the user to be held in a PHP variable so it can be submitted into a database.

The prompt will works so just confused as to how to store it to a PHP variable.

This is the JS code for the prompt box.
Code:
function failComment()
{
var x;

var comment=prompt("Please enter a comment as to why the test failed!","");

if (comment!=null)
  {
  x=comment;
   }
}

Any suggestion would be great, thanks.
 
should have mentioned that the JS prompt box is on the actual submission page. The user enters data into a table then hits submit, it then checks the data via these IF statements. So if it falls under the fail IF statement then I want the user to enter a comment. So I cant really POST again cause I have POSTed the previous pages form values to this page. If you know what I mean! lol
 
Instead of showing an ugly prompt dialog when those conditions are met, why not dynamically show/hide a textarea element for the user to type the details in to.

Much nicer UI, and better UX for the user as there are no unexpected alerts.

Yea that sounds a better option. How would I show/hide a text area?

Would you just have it hidden on the initial form and if it fails then show the hidden comments box? Which brings my next question, how would I unhide the textarea?

Sorry, but im not strong on this stuff! lol
 
Back
Top Bottom