Jump to content

HTML Editor Help


Spixxx

Recommended Posts

[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??
Link to comment
https://forums.phpfreaks.com/topic/5088-html-editor-help/
Share on other sites

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
Link to comment
https://forums.phpfreaks.com/topic/5088-html-editor-help/#findComment-18033
Share on other sites

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.