Jump to content


Photo

HTML Editor Help


  • Please log in to reply
1 reply to this topic

#1 Spixxx

Spixxx
  • Members
  • PipPip
  • Member
  • 29 posts

Posted 16 March 2006 - 04:06 PM

<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>

It works when I click Bold Text, it inserts the
<b>Your Text Here</b>
But when I try advanced mode, it still inserts ^THAT instead of
<b></b>

What did I do wrong??

#2 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 16 March 2006 - 04:33 PM

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:
<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>


good luck
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users