Results 1 to 3 of 3

Thread: Help With BBcode Inserter

  1. #1
    Join Date
    Mar 2008
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Help With BBcode Inserter

    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
    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+"[s]"+promdata+"[/s]"}
       
                         }
    
    
      ifelse(bbcalled == 'o'){
        var promdata=prompt("Please enter the text you wish to be overlined.","");
        if(promdata != ""){commentform.message.value=commentform.message.value+"[o]"+promdata+"[/o]"}
       
                         }
    
    
      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+"[color="+colordata+"]"+promdata+"[/color]"}
       
                         }
    
    
      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+"[size="+sizedata+"]"+promdata+"[/size]"}
       
                         }
    
    
      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+"[img]"+promdata+"[/img]"}
       
                         }
    
    
      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+"[mail]"+promdata+"[/mail]"}
       
                         }
    }
    </script>
    The error line (also the dropdown menu)

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

  2. #2
    Join Date
    Aug 2007
    Location
    Ohio
    Posts
    79
    Thanks
    0
    Thanked 15 Times in 15 Posts

    Default

    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.

  3. The Following User Says Thank You to jackbenimble4 For This Useful Post:

    Belvit (03-31-2008)

  4. #3
    Join Date
    Mar 2008
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    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.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •