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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.