Spixxx Posted March 16, 2006 Share Posted March 16, 2006 [code]<script language="javascript">beg = "on";adv = "off";function mode(level){if(level == "beg"){beg = "on";adv = "off";}if(level == "adv"){beg = "off";adv = "on";}}function bold() {if(beg == "on"){document.editor.area.value = document.editor.area.value + "<b>\nYour Text Here\n</b>";}if(adv == "on"){document.editor.area.value = document.editor.area.value + "<b></b>";}}</script><form name="editor"><textarea name="area" rows="6" cols="25"></textarea><br><b>Mode: </b><input type="radio" name="mode" onclick="mode(beg)" checked>Begginer <input type="radio" name="mode" onclick="mode(adv)">Advanced<br><input type="button" value="Bold" onClick="bold()"><br><input type="submit" name="submit" value="Submit"></form>[/code]It works when I click Bold Text, it inserts the[code]<b>Your Text Here</b>[/code]But when I try advanced mode, it still inserts ^THAT instead of[code]<b></b>[/code]What did I do wrong?? Quote Link to comment https://forums.phpfreaks.com/topic/5088-html-editor-help/ Share on other sites More sharing options...
obsidian Posted March 16, 2006 Share Posted March 16, 2006 it's simply the name of your functions that's throwing you off. "mode" and "bold" are both keywords that you can't use as function names. i've rewritten a couple other ideas you may want to consider... try using boolean values instead of your "on" and "off" for easier checking. here's what i came up with:[code]<script language="javascript">var beg = true;var adv = false;function myMode(level){if(level == "beg"){ beg = true; adv = false;} else if(level == "adv") { beg = false; adv = true;}}function doBold() {if(beg){document.editor.area.value = document.editor.area.value + "<b>\nYour Text Here\n</b>";}if(adv){document.editor.area.value = document.editor.area.value + "<b></b>";}}</script><form name="editor"><textarea name="area" rows="6" cols="25"></textarea><br><b>Mode: </b><input type="radio" name="mode" onclick='myMode("beg");' checked>Begginer <input type="radio" name="mode" onclick="myMode('adv')">Advanced<br><input type="button" value="Bold" onClick="doBold()"><br><input type="submit" name="submit" value="Submit"></form>[/code]good luck Quote Link to comment https://forums.phpfreaks.com/topic/5088-html-editor-help/#findComment-18033 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.