Petty_Crim Posted October 7, 2007 Share Posted October 7, 2007 I'm having a go at making bbcode for a forum i'm making. Basically a user pushes a button and the javascript sticks something into the textarea. I'm starting with the bold button but I can't seem to get it working, theres no syntax errors but the page just reloads a blank page and sits there loading for some reason. <?php echo "<script type='text/javascript'> <!-- Begin function write() { form.body.focus(); form.body.value = ''; } // End --> </script>"; echo "Create Post<br>"; echo "<form>"; echo "<table border='0'>"; echo "<tr><td><input name='bold' type='button' value='Bold' onClick='write()'/></td></tr>"; echo "<tr><td><textarea name='body' cols='40' rows='10'></textarea></td></tr>"; echo "</table></form>"; ?> Link to comment https://forums.phpfreaks.com/topic/72166-adding-javascript-into-php/ Share on other sites More sharing options...
ludjer Posted October 7, 2007 Share Posted October 7, 2007 i would advise using a link instead of a button. here is a example, i dont know to much about java script but i think this is how you would do it: <a href="javascript:void(0);" onclick="java function"><img src"button.jpg></a> Link to comment https://forums.phpfreaks.com/topic/72166-adding-javascript-into-php/#findComment-363891 Share on other sites More sharing options...
Petty_Crim Posted October 7, 2007 Author Share Posted October 7, 2007 I want to do it with a button, not a link. Link to comment https://forums.phpfreaks.com/topic/72166-adding-javascript-into-php/#findComment-363913 Share on other sites More sharing options...
yzerman Posted October 7, 2007 Share Posted October 7, 2007 ok - why exactly do you need to enclose this in php tags? Rewrite your code: <?php //if you want to do something in php you can do it here ?> <script type='text/javascript'> <!-- Begin function write() { form.body.focus(); form.body.value = ''; } // End --> </script> Create Post <form> <table border='0'> <tr><td><input name='bold' type='button' value='Bold' onClick='write()'/></td></tr> <tr><td><textarea name='body' cols='40' rows='10'></textarea></td></tr> </table></form> <?php //if you want to do something in php you can do it here ?> For the actual code - don't be ashamed to look at other peoples javascript (hint, when you reply to this post, right click and view the source ) Anyone who is learning a new style of coding should be able to learn from other peoples work. Link to comment https://forums.phpfreaks.com/topic/72166-adding-javascript-into-php/#findComment-363922 Share on other sites More sharing options...
Petty_Crim Posted October 16, 2007 Author Share Posted October 16, 2007 ok - why exactly do you need to enclose this in php tags? Rewrite your code: <?php //if you want to do something in php you can do it here ?> <script type='text/javascript'> <!-- Begin function write() { form.body.focus(); form.body.value = ''; } // End --> </script> Create Post <form> <table border='0'> <tr><td><input name='bold' type='button' value='Bold' onClick='write()'/></td></tr> <tr><td><textarea name='body' cols='40' rows='10'></textarea></td></tr> </table></form> <?php //if you want to do something in php you can do it here ?> For the actual code - don't be ashamed to look at other peoples javascript (hint, when you reply to this post, right click and view the source ) Anyone who is learning a new style of coding should be able to learn from other peoples work. Will this work with an include? ie I have a main page template called main.php which I use for all my pages, inside that main I use include to include the different pages in a content area. Will having the javascript out of the php tags still work? Link to comment https://forums.phpfreaks.com/topic/72166-adding-javascript-into-php/#findComment-370433 Share on other sites More sharing options...
Petty_Crim Posted October 16, 2007 Author Share Posted October 16, 2007 Also your code doesn't seem to do anything but continuously loop. I click bold it just goes to a blank page that sits and loads forever. Link to comment https://forums.phpfreaks.com/topic/72166-adding-javascript-into-php/#findComment-370435 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.