PDA

View Full Version : Help With BBcode Inserter



Belvit
03-31-2008, 12:52 AM
I made a 'bbcode inserter' for my comment form, it is basically a select box that brings up a prompt asking about what you want in the bbcode, there wasn't much scripts out there for this 'simplcilty' (consider that the website is quite limtited to space) so I decided that I would make my own and it was ment to be 'finished' but there always seems to be a error with it, and I did fix some would-be errors but I have not managed to get this error.

to produce this error: click on the dropdown menu 'bbcode' as it has a onchange value.

URL: http://scaryghosts.org/comment.php

'BBCODE Inserter' Script Code

<script type="text/javascript">
function insertbbcode(bbcalled)
{
var commentform = document.getElementById("submitcomment");
if(bbcalled == 'b'){
var promdata=prompt("Please enter the text you wish to be bold,","");
if(promdata != ""){commentform.message.value=commentform.message.value+""+promdata+""}

}

ifelse(bbcalled == 'i'){
var promdata=prompt("Please enter the text you wish to be italic.","");
if(promdata != ""){commentform.message.value=commentform.message.value+""+promdata+""}

}

ifelse(bbcalled == 'u'){
var promdata=prompt("Please enter the text you wish to be underlined.","");
if(promdata != ""){commentform.message.value=commentform.message.value+""+promdata+""}

}

ifelse(bbcalled == 's'){
var promdata=prompt("Please enter the text you wish to be striked out.","");
if(promdata != ""){commentform.message.value=commentform.message.value+""+promdata+""}

}


ifelse(bbcalled == 'o'){
var promdata=prompt("Please enter the text you wish to be overlined.","");
if(promdata != ""){commentform.message.value=commentform.message.value+""+promdata+""}

}


ifelse(bbcalled == 'col'){
var colordata=prompt("Please enter the color you wish your text to be (EG red).","");
var promdata=prompt("Please enter the text you wish to see colored.","");
if(promdata != "" || colordata != "" ){commentform.message.value=commentform.message.value+""+promdata+""}

}


ifelse(bbcalled == 'siz'){
var sizedata=prompt("Please enter the size you wish your text to be (EG 10).","");
var promdata=prompt("Please enter the text you wish to see sized.","");
if(promdata != "" || sizedata != "" ){commentform.message.value=commentform.message.value+""+promdata+""}

}


ifelse(bbcalled == 'font'){
var fontdata=prompt("Please enter the font you wish your text to be (EG Times New Roman).","");
var promdata=prompt("Please enter the text you wish to see with the font.","");
if(promdata != "" || fontdata != "" ){commentform.message.value=commentform.message.value+""+promdata+""}

}


ifelse(bbcalled == 'img'){
var promdata=prompt("Please enter the URL of the image you wish to be displayed (EG http://www.webiste.com/image.gif).","");
if(promdata != ""){commentform.message.value=commentform.message.value+""+promdata+""}

}


ifelse(bbcalled == 'url'){
var promdata=prompt("Please enter the URL you wish to be displayed (EG http://www.webiste.com/).","");
if(promdata != ""){commentform.message.value=commentform.message.value+""+promdata+""}

}


ifelse(bbcalled == 'mail'){
var promdata=prompt("Please enter the email you wish to be displayed (EG me@hotmail.co.uk).","");
if(promdata != ""){commentform.message.value=commentform.message.value+""+promdata+""}

}
}
</script>

The error line (also the dropdown menu)



ERROR LINE: <select style="margin-top:5px;border: 1px solid #000;font-family:Shruti;font-size:11px;padding-left:1px;" name="bbcode" onchange="insertbbcode(this.options[selectedIndex].value);this.selectedIndex=0;">
<option selected="selected" value="">BBCode</option>
<option value="b">Bold</option>
<option value="i">Italic</option>
<option value="u">Underlined</option>
<option value="s">Strikethrough</option>
<option value="o">Overlined</option>
<option value"col">Colored Text</option>
<option value"siz">Sized Text</option>
<option value="font">Font</option>
<option value="img">Image</option>
<option value="url">URL</option>
<option value="mail">Email</option>
</select>


For anybody that helps me I give them a big: :D

jackbenimble4
03-31-2008, 02:30 AM
In the function insertbbcode you're using "ifelse". It's an easy mistake to make, but the correct structure is "else if". It's easy to remember if you think about what it is -- a combination of if and else.

If you change each ifelse to elseif, I think it should work. FireBug gives the error that insertbbcode is undefined, which is probably because of this syntax typo.

Belvit
03-31-2008, 03:04 AM
Oh, I thougth of it as 'if' something 'else'...
Its working now I thougth it was something to do with the onchange event =/ so I mostly concentrated on the event, constantly looking over it.