Send variables between Javascript, Form and PHP on the same page

Posted on Juli 7, 2008. Filed under: Tutorial Programming | Tag:, , |

PHP variable to Javascript variable:

	<?php   $myvar=10;   ?>

	<script type="text/javascript">
		jsvar = <?php echo $myvar; ?>
		document.write(jsvar);  // Test to see if its prints 10:
	</script>

Form variable to Javascript variable:

	<form name="myform4">    <input type="hidden" name="formvar" value="100">     </form>

	<script type="text/javascript">
		jsvar = document.myform4.formvar.value;
		document.write(jsvar) // test
	</script>

PHP variable to Form variable:

	<form name="myform4">
		<input type="hidden" name="formvar" value="<?php phpvar=10; echo phpvar; ?>"> // PHP code inside HTML!!
	</form>

(lebih…)

Baca Pos Lengkap | Make a Comment ( None so far )

Liked it here?
Why not try sites on the blogroll...