robert_gsfame Posted December 11, 2009 Share Posted December 11, 2009 i have this <form name="form1" method="post"> <input type="text" id="textbox"> <input type="button" onclick="function()"> </form> Let say function() will validate the textbox, if textbox is empty then alert box will appear and once filled it will go to the page whatever i put inside this function window.location() I usually get the textbox value as i parse it through the url, and later i use $_GET to get the value....my question : is it possible to get the value using $_POST instead of getting it through url using $_GET THANKS Link to comment https://forums.phpfreaks.com/topic/184780-get-post-in-javascript/ Share on other sites More sharing options...
Adam Posted December 11, 2009 Share Posted December 11, 2009 I think it's only possible by echoing the json encoded (json_encode) $_POST array into the JavaScript. Link to comment https://forums.phpfreaks.com/topic/184780-get-post-in-javascript/#findComment-975499 Share on other sites More sharing options...
robert_gsfame Posted December 12, 2009 Author Share Posted December 12, 2009 as i am still new to javascript, i dont have any idea about json_encoded()....anyway thanks! or maybe anyone could give more inputs regarding this:D Link to comment https://forums.phpfreaks.com/topic/184780-get-post-in-javascript/#findComment-975869 Share on other sites More sharing options...
ngreenwood6 Posted December 12, 2009 Share Posted December 12, 2009 you could change your form to something like this: <form id="form1" action="somepage.php" method="post"> <input type="text" id="textbox1"> <input type="button" onclick="someFunction()"> </form> then your javascript would look like this: function someFunction(){ //get the form var form1 = document.getElementById('form1'); //check the form if(document.getElementById('textbox1').value != ''){ //submit the form form1.submit(); } else { //show alert on error alert('Please fill in text box'); } } Basically all this does is submit the form after checking that your criteria is met. It will submit it as a POST instead of a GET. Please ask if you have any questions. Link to comment https://forums.phpfreaks.com/topic/184780-get-post-in-javascript/#findComment-975880 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.