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.
Results 1 to 9 of 9
  1. #1
    New Coder
    Join Date
    Oct 2005
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts

    help with onchange

    Hi, im trying to load the value of an option like this

    Code:
    <select class="textbox" onchange="javascript:createBBtag('font here','','message')">
    <option value="-">Font Name</option>
    <option value="Arial">Arial</option>
    <option value="Book Antiqua">Book Antiqua</option>
    <option value="Comic Sans Ms">Comic Sans Ms</option>
    <option value="Courier New">Courier New</option>
    <option value="Georgia">Georgia</option>
    <option value="Impact">Impact</option>
    <option value="Lucida Sans">Lucida Sans</option>
    <option value="Times New Roman">Times New Roman</option>
    <option value="Trebuchet MS">Trebuchet MS</option>
    <option value="Tahoma">Tahoma</option>
    <option value="Verdana">Verdana</option>
    </select>
    When i select the font, id like it to load into the font= tag in the onchange handler. I tried this.form.value but im still new to Javascript, and obviously didnt do it right, please help.

  • #2
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    Your onchange should be something like this

    PHP Code:
    onchange="javascript:createBBtag(this.options[selectedIndex].value,'','message')" 
    The silent one.

    The most dangerous thing in the world is an idea.
    The most dangerous person in the world is the one with an idea.

  • #3
    New Coder
    Join Date
    Oct 2005
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for the help, although im having trouble getting this to work right still.

    onchange="javascript:createBBtag('[font=this.options[selectedIndex].value]','[/font]','message')"

    i need it to read [.font="font"]

    its printing to the textbox [font=this.options[selectedIndex].value][/font]

  • #4
    New Coder
    Join Date
    Oct 2005
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts
    is their no way to do this?

  • #5
    New Coder
    Join Date
    Oct 2005
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok, so can someone tell me where i could go to get an answer for this question since no one here seems to be able to answer it?

  • #6
    Regular Coder
    Join Date
    Jan 2003
    Posts
    867
    Thanks
    4
    Thanked 8 Times in 8 Posts
    Quote Originally Posted by Sayian
    Ok, so can someone tell me where i could go to get an answer for this question since no one here seems to be able to answer it?
    I can tell you exactly where to go.

    Unless you're paying me, or at least being polite and explaining your problem well, what can you really expect?

    Anyways, you didn't show your existing form, javscript function, or even explain what you want to happen when the onchange triggers. Here's some code I wrote up that may or may not do what you're looking for. The important part is that you want: [font='+this.options[selectedIndex].value+']

    <html>
    <head>
    <script language="javascript">
    function createBBtag(tagtype, whichfont){
    if (tagtype=='font')
    document.myform.messagebox.value += '<font='+whichfont+'></font>'; //forum doesn't allow square brackets so I made them arrow brackets
    }
    </script>
    </head>
    <body>

    <form name="myform">

    <select class="textbox" onchange="createBBtag('font', this.options[selectedIndex].value)">
    <option value="-">Font Name</option>
    <option value="Arial">Arial</option>
    <option value="Book Antiqua">Book Antiqua</option>
    <option value="Comic Sans Ms">Comic Sans Ms</option>
    <option value="Courier New">Courier New</option>
    <option value="Georgia">Georgia</option>
    <option value="Impact">Impact</option>
    <option value="Lucida Sans">Lucida Sans</option>
    <option value="Times New Roman">Times New Roman</option>
    <option value="Trebuchet MS">Trebuchet MS</option>
    <option value="Tahoma">Tahoma</option>
    <option value="Verdana">Verdana</option>
    </select>

    <br>

    <textarea name="messagebox"></textarea>

    </form>
    </body>
    </html>
    Last edited by arnyinc; 01-29-2006 at 01:54 AM.

  • #7
    New Coder
    Join Date
    Oct 2005
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you, i am grateful. 1 question, would this code work in both IE and Firefox?

  • #8
    Regular Coder
    Join Date
    Jan 2003
    Posts
    867
    Thanks
    4
    Thanked 8 Times in 8 Posts
    Yep, it should. I tested it out in FireFox and IE6. Hope it works out for you.

  • #9
    New Coder
    Join Date
    Oct 2005
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks, i actually have it working right now. I really appriciate it, theirs only 1 problem im facing though, for some reason i cant nest tags.

    Im not really sure what could be causing this, do i need more code to be able to nest tags?


  •  

    Posting Permissions

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