sseeley Posted June 5, 2009 Share Posted June 5, 2009 If I have a value $test in PHP how can I get this value using Java script, I would like to use this is a form validation? Many thanks in advance? Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted June 5, 2009 Share Posted June 5, 2009 When you generate the page from PHP, include this in the output: <?php echo sprintf( '<input type="hidden" name="hdnTest" id="hdnTest" value="%s" />', htmlentities( $test, ENT_QUOTES ) ); ?> If $test has 'Hello World' in it, then that should output: <input type="hidden" name="hdnTest" id="hdnTest" value="Hello World" /> Then in JavaScript you can: alert( document.getElementById( 'hdnTest' ).value ); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.