Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    Regular Coder
    Join Date
    Mar 2004
    Posts
    232
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Insert BB with onchange

    I have some BB code that I am inserting with JavaScript but it isn't working...
    I have this code but it comes up "undefined"

    Code:
    <SELECT Onchange='Javascript: document.post.comments.value += "[Size=" + this.SelectedIndex.value + "] [/Size]"'>
    <option Value="default">Default</option>
    <option Value="red" style="font-color: red">Red</option>
    </SELECT>

  • #2
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Try one of the following (instead of this.SelectedIndex.value):
    Code:
    this.value
    or
    Code:
    this.options[this.selectedIndex].value
    Let me know how that works out for you.
    Sadiq.

  • #3
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The value Red is not a size.
    Are you looking for the index which would be 1 if Red was chosen?
    If so, remove the value.

    eg: this.options[this.selectedIndex]

    .....Willy

  • #4
    Regular Coder
    Join Date
    Mar 2004
    Posts
    232
    Thanks
    0
    Thanked 0 Times in 0 Posts
    sad69's idea worked. Yeah red is not a size. That was a stupid color/font screw up. And it works just like this forum

    www.hostultra.com/~stophon4/guestbook/gb.php

  • #5
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sort of.. couple of bugs on that guest book, but pretty neat still!

    Main thing for me is that if you select some text and press on of the buttons, it doesn't recognize that you've selected anything and expects new inputs.. but that's not a huge deal I suppose..

    Also, when using the buttons (like bold or whatever) and pressing cancel results in a null. But you might already know about that..

    Pretty cool though, good job!

    Sadiq.

  • #6
    Regular Coder
    Join Date
    Mar 2004
    Posts
    232
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks, yeah I think I know how to stop the null thing from happening, but I don't know how to do the highlight thing, what function reonizes what text is highlighted?

    Anyway the guestbook works great except for that stuff :thumbsup:
    Well at least in JavaScript way, there is this php bug that makes it so whenever you put a ' or " it puts a slash in there :confused:

    EDIT:
    Well I thought I new what to do for the null thing, but it still comes up null and nothing changes...
    Code:
    function Bold()
    {
    	var bold =prompt("Please enter the text you wish to appear in bold:", "")
    	if(bold == 'null')
    	{ 
    	document.post.comments.value += "";
    	}else{
    	document.post.comments.value += "" + bold + ""
    	}
    }
    Last edited by stophon4; 04-30-2004 at 02:45 PM.

  • #7
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Maybe remove the quotes around null? ie. 'null' => null

    As for detecting the selection, check out this link:
    http://www.faqts.com/knowledge_base/.../18053/fid/145

    As for the ' " problem in php, try using the stripslashes() method when echoing out a guestbook entry.

    Hope that helps,
    Sadiq.

  • #8
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Actually I was just re-reading that link and there's a typo: the r should be a w.

    I've altered it slightly to show you how to stick in whatever you want (bolding in my example):
    Code:
    <html>
     <head>
      <script>
       function formatSelected(from_obj, formatting) {
        from_obj.focus ();
        var w = self.document.selection.createRange ();
        w.text = "["+formatting+"]"+w.text+"[/"+formatting+"]";
       }
      </script>
     </head>
     <body>
      <textarea id = "forSELECT" cols = "30" rows = "10">some text some text some text...</textarea>
      <p>
      <input type = "button" value = "View selected" onclick = "formatSelected(forSELECT, 'b');">
      </p>
     </body>
    </html>
    Hope that helps,
    Sadiq.

  • #9
    Regular Coder
    Join Date
    Mar 2004
    Posts
    232
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by sad69
    Actually I was just re-reading that link and there's a typo: the r should be a w.

    I've altered it slightly to show you how to stick in whatever you want (bolding in my example):
    Code:
    <html>
     <head>
      <script>
       function formatSelected(from_obj, formatting) {
        from_obj.focus ();
        var w = self.document.selection.createRange ();
        w.text = "["+formatting+"]"+w.text+"[/"+formatting+"]";
       }
      </script>
     </head>
     <body>
      <textarea id = "forSELECT" cols = "30" rows = "10">some text some text some text...</textarea>
      <p>
      <input type = "button" value = "View selected" onclick = "formatSelected(forSELECT, 'b');">
      </p>
     </body>
    </html>
    Hope that helps,
    Sadiq.
    KK, I got the null thing working and also the stripslashes() thing working, but I don't understand how you did the bold highlight (above) maybe you should explain it a little bit more, sorry for not understanding

  • #10
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok.. which part don't you understand?

    There's a button, right? Do you see the onClick event on the button? It calls the function (formatSelected) that inserts some formatting around the selected text.

    The function formatSelected takes two parameters: the textarea and the formatting you want (I pass 'b' as I want [ b] .. [ /b] to show up). The function then grabs the selected text, and then I insert the [, the formatter and ], the selected text, the [/, the formatter, and the ]. And that's it.

    If you're still lost, let me know what part you don't understand..

    Sadiq.

  • #11
    Regular Coder
    Join Date
    Mar 2004
    Posts
    232
    Thanks
    0
    Thanked 0 Times in 0 Posts


    Maybe you should explain each part of the code, and also is w.text the highlighted variable?

  • #12
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    is w.text the highlighted variable?
    Yep.

    I just explained the entire code.

    Why don't you break down the code that you DO understand, and the code that you DON'T understand.

    Sadiq.

  • #13
    Regular Coder
    Join Date
    Mar 2004
    Posts
    232
    Thanks
    0
    Thanked 0 Times in 0 Posts
    OK, I got alot farther this time, but the text box says [object], not what I have highlighted, here is the code:
    Code:
    function Bold(from_obj, formatting)
    {
    	from_obj.focus ();
        var w = self.document.selection.createRange ();
    	var bold =prompt("Please enter the text you wish to appear in bold:", "" + w +"")
    	if(bold == null)
    	{ 
    	document.post.comments.value += "";
    	}else{
    	document.post.comments.value += "" + bold + ""
    	}
    }

  • #14
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    var bold =prompt("Please enter the text you wish to appear in bold:", "" + w +"")
    should read:
    Code:
    var bold = prompt("Please enter the text you wish to appear in bold:", "" + w.text +"");
    Let me know how that works out for you.

    Sadiq.

  • #15
    Regular Coder
    Join Date
    Mar 2004
    Posts
    232
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by sad69
    Code:
    var bold =prompt("Please enter the text you wish to appear in bold:", "" + w +"")
    should read:
    Code:
    var bold = prompt("Please enter the text you wish to appear in bold:", "" + w.text +"");
    Let me know how that works out for you.

    Sadiq.
    You can see for yourself what it does


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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