blueman378 Posted May 5, 2008 Share Posted May 5, 2008 hi guys, well im making an application and i need to submit the value of a javascript varialbe to a php page, the varialbe contains very long strings so get is not appropriate, so how would i send the javascript variable through post? Link to comment https://forums.phpfreaks.com/topic/104176-javascript-varialbe-to-php-via-post/ Share on other sites More sharing options...
dooper3 Posted May 5, 2008 Share Posted May 5, 2008 you could do something like set it as a hidden value in a form field, I don't know how you get the variable in javascript but you could do something like this: <script language="text/javascript"> function putinform(javascript_variable) { document.getElementById('hiddenformfield').value=javascript_variable; } </script> <form action="<?php $php_self ?>" method="post"> <input type="hidden" value="" id="hiddenformfield" /> </form> then just call the function when you are ready and put the js variable inside the function, then when you trigger the form to submit it will transfer the value of the variable through the hidden input field as $_POST['hiddenformfield']. Hope that helps. Link to comment https://forums.phpfreaks.com/topic/104176-javascript-varialbe-to-php-via-post/#findComment-533322 Share on other sites More sharing options...
blueman378 Posted May 5, 2008 Author Share Posted May 5, 2008 well heres the code: (minus all the back crap) <html> <head> <title>Web Spirited - BBcode editor</title> </head> <body> <div align="center" > <table border="0" width="800" > <tr> <td><b><font face="Verdana">Preview Submit</font></b></td> </tr> <tr> <td><hr></td> </tr> <tr> <td><div id="preview_innerhtml" style="overflow:auto;height:100px;width:100%;border:2px solid #6593CF;background-color:#DBE6F3;font-family: Verdana, Tahoma, Arial;font-size:12px;"></div></td> </tr> <tr> <td><b><font face="Verdana">BBCode Output</font></b><br><textarea name="message" id="message" style="width:100%;height:100px;"></textarea></td> </tr> </table> </div> <div align="center"> <table border="0" width="800"> <tr> <td align=center> <style type='text/css'>@import url(styles/office2007/style.css);</style> <script language="JavaScript" type="text/javascript" src="editor.js?version=4.2"></script> <script language="JavaScript" type="text/javascript"> var getdata ="[b]Test me[/b]"; //Flag "min" will show Mini toolbar - "max" will show 2 toolbars - config inside editor.js Instantiate("min","editor", getdata , "600px", "200px"); function get_hoteditor_data(){ setCodeOutput(); var html_output = document.getElementById("hoteditor_html_ouput_editor").value;//Output to HTML code var bbcode_output=document.getElementById("hoteditor_bbcode_ouput_editor").value;//Output to BBCode document.getElementById("message").value = bbcode_output; document.getElementById("preview_innerhtml").innerHTML=html_output; } </script> </td> </tr> <tr> <td align=center><a href=# onclick="get_hoteditor_data();"><b>[submit / Preview]</b></a></td> </tr> </table> </div> </body> </html> so would doing this work: function get_hoteditor_data(){ setCodeOutput(); var html_output = document.getElementById("hoteditor_html_ouput_editor").value;//Output to HTML code var bbcode_output=document.getElementById("hoteditor_bbcode_ouput_editor").value;//Output to BBCode document.getElementById("bfield").value = bbcode_output; document.getElementById("hfield").innerHTML=html_output; } </script> <form name="a" id="a" method="post" action="file.php"> <input type="hidden id=hfield" name="hfield" value=""> <input type="hidden id=bfield" name="bfield" value=""> </form> obviously ignoring the fact that the form has no submit ect, im more taling about the function, would that work? Link to comment https://forums.phpfreaks.com/topic/104176-javascript-varialbe-to-php-via-post/#findComment-533325 Share on other sites More sharing options...
blueman378 Posted May 5, 2008 Author Share Posted May 5, 2008 modify isnto working, but minor correction, function get_hoteditor_data(){ setCodeOutput(); var html_output = document.getElementById("hoteditor_html_ouput_editor").value;//Output to HTML code var bbcode_output=document.getElementById("hoteditor_bbcode_ouput_editor").value;//Output to BBCode document.getElementById("bfield").value = bbcode_output; document.getElementById("hfield").value=html_output; } </script> <form name="a" id="a" method="post" action="file.php"> <input type="hidden" id=hfield" name="hfield" value=""> <input type="hidden" id=bfield" name="bfield" value=""> </form> Link to comment https://forums.phpfreaks.com/topic/104176-javascript-varialbe-to-php-via-post/#findComment-533326 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.