Jump to content

javascript varialbe to php via post?


blueman378

Recommended Posts

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.

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?

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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.