SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Radio Button Problem

    Hey,

    I have searched the forums, looked around, tested multiple things, but mine doesn't work

    Radio buttons:
    [ <input type='radio' name='mode' value=\"0\" checked=\"checked\"> Enhanced | <input type='radio' name='mode' value=\"1\"> Normal Mode ]

    JS:

    if (document.bbcode.mode[1].checked == true)
    {
    alert("Test1");
    }
    if (document.bbcode.mode[1].checked == true)
    {
    alert("Test2");
    }

    Doesn't seem to work

    I get "Undefined object document.bbcode.mode"

    Any ideas?

    Regards,
    Someonewhois

  2. #2
    SitePoint Addict
    Join Date
    May 2000
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if bbcode is your form name then this should work:
    if(document.bbcode.mode[0].checked)
    {alert("1st radio checked!" )}
    if(document.bbcode.mode[1].checked)
    {alert("2nd radio checked!" )

    Really need to see the rest of your code to see if something else is not causing the problem.

  3. #3
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    bbcode is my form.

    I hope this isn't considered advertising, but here's the page.. http://forums.sowibb.com/post.php?act=view&page=5

    It's a post page. Just view source if you have to.

    With the code you gave, I get "document.bbcode.mode is not an object" twice.

    Strange..

  4. #4
    SitePoint Addict
    Join Date
    May 2000
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I went to the link you provided and I do not find the form "bbcode" or the raido buttons "mode".

  5. #5
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
                    <input type='button' value='B' onClick='bold()' name='Bold' style="font-weight:bold">
                    <
    input type='button' value='I' onClick='italic()' name='Italic' style="font-style:italic">
                    <
    input type='button' value='U' onClick='under()' name='Underline' style="text-decoration:underline">
                    <
    input type='button' value='Quote' onClick='quote()'>&nbsp;
                    <
    input type='button' value='Code' onClick='code()'>&nbsp;
                      <
    input type='button' value='Image' onClick='image()'>&nbsp;
                    <
    input type='button' value='URL' onClick='url()'>&nbsp;
                    <
    input type='button' value='E-mail' onClick='email()'>
                <
    BR>
                <
    SELECT name='face'><option onClick='font("Arial")'>Arial</option><option onClick='font("Times New Roman")'>Times New Roman</option><option onClick='font("Verdana")'>Verdana</option><option onClick='font("System")'>System</option><option onClick='font("Courier New")'>Courier New</option></SELECT>&nbsp;<SELECT name='size' onChange="size(this.options[this.selectedIndex].value)"><option value=1>Size 1</option><option value=2>Size 2</option><option value=3>Size 3</option><option value=5>Size 5</option><option value=10>Size 10</option></SELECT>
                <
    form name="bbcode">[ <input type='radio' name='mode' value="0" checked="checked" onClick="change(0)"Enhanced | <input type='radio' name='mode' value="1" onClick="change(1)"Normal Mode ]</form></span>
                </
    p
    Is the form

    PHP Code:
    if(document.bbcode.mode[0].checked)
    alert("1st radio checked!") }
    if(
    document.bbcode.mode[1].checked)
    alert("2nd radio checked!") }
                
    //-->
                
    </script> 
    is the JS.

    Regards,
    Someonewhois

    [ Edit: Using PHP instead of CODE tags because CODE tags don't seem to produce new lines.. ]

  6. #6
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hm, it can't be anything interfering with it, because I made a test.html file with this in it:

    PHP Code:
    <script>
    if(
    document.bbcode.mode[0].checked
    alert("1st radio checked!" ) } 
    if(
    document.bbcode.mode[1].checked
    alert("2nd radio checked!" ) } 
    </script> 

    <form name="bbcode">
    [ <input type='radio' name='mode' value="0" checked="checked"> Enhanced 
    | <input type='radio' name='mode' value="1"> Normal Mode ]</form> 
    And it still doesn't work

  7. #7
    SitePoint Zealot Drew630's Avatar
    Join Date
    Nov 2001
    Location
    Maryland
    Posts
    175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Found the problem. You need to actually call the Javascript that you want to use. Your code never referenced the JS. Not only that, but to refernce the JS, you need to put it in a function, if you don't include it in the HTML.

    This is your code snippet fixed.

    Code:
    <html>
    <body>
    <script> 
    function check() {
     if(document.bbcode.mode[0].checked) 
     { alert("1st radio checked!" ) } 
     if(document.bbcode.mode[1].checked) 
     { alert("2nd radio checked!" ) } 
    }
    </script> 
    <form name="bbcode"> 
    [ <input type='radio' name='mode' value="0" checked="checked" onclick="check();"> Enhanced 
    | <input type='radio' name='mode' value="1" onclick="check();"> Normal Mode ]
    </form>  
    </body>
    </html>
    Hope this helps.

    Drew
    ~Drew

    There Is No Greater Joy Than Soaring High On The Wings Of Your Dreams, Except Maybe The Joy Of Watching A Dreamer Who Has Nowhere To Land But In The Ocean Of Reality.

  8. #8
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have you seen my TAEditor?

    It's super easy to configure
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  9. #9
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Drew - Hm, I see.

    So before I had an big IF to either do the first set or second set of functions - you are saying I should put that if in each function?

    Regards,
    Someonewhois

  10. #10
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    THANK YOU!

    It worked!

    Oh, and beetle, thanks for the link anyhow.

  11. #11
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No problemo
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  12. #12
    SitePoint Zealot Drew630's Avatar
    Join Date
    Nov 2001
    Location
    Maryland
    Posts
    175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry, I was away for the weekend.

    So before I had an big IF to either do the first set or second set of functions - you are saying I should put that if in each function?
    Well, I am going to assume that you do not have a traditional coding background here. I apologize in advance if I am mistaken.

    To try and make this as short and simple without a long explanation of coding structure, basically you have 2 options using JS: you can insert it into the HTML, or you can call a function from your HTML. For something like a field-check function that will be used more than once, you should put this in a function that you can call as many times as is necessary.
    That is why I put your IF stmt in a function, since you want to check more than one field. Then, you can call your function from event-handlers of the HTML tags you use.

    Make sense?

    Overall, glad I could help

    Drew
    ~Drew

    There Is No Greater Joy Than Soaring High On The Wings Of Your Dreams, Except Maybe The Joy Of Watching A Dreamer Who Has Nowhere To Land But In The Ocean Of Reality.


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
  •