www.webdeveloper.com
Results 1 to 4 of 4

Thread: if (optionButton.checked = true){}

  1. #1
    Join Date
    Sep 2011
    Posts
    64

    if (optionButton.checked = true){}

    Hello,

    I am creating a study exam for myself to prepare for a test. I have written my first question which is a true/false. I am using option buttons like:

    <input type='radio' id='Q1T' name='TF1' value='True' />
    <input type='radio' id='Q1F' name='TF1' value='False'/>

    Take notice to the id ('Q1T' and 'Q1F') which stands for "Question One True" and "Question One False". Okay, they both have the same name property so that you can only select one or the other. Ok, Ok, enough of the html refresher...

    I have a button...

    <input type='button' id='Q1S' name='Q1S' value='Enter' onclick='CheckQ1();' />

    yup, so when the button is clicked, the "CheckQ1" or "Check Question One" function that is written in a separate .js file will run...

    This one works:

    function CheckQ1()
    {
    var rButtonT = document.getElementById('Q1T');
    alert(rButtonT.checked);
    }

    When the true option is selected the alert says true and when the false option is selected the alert says false. Well, then why does the following script give me unexpected results...

    fucntion CheckQ1()
    {
    var rButtonT = document.getElementById('Q1T');
    if (rButtonT.checked = true)
    {
    var Answer = document.getElementById('Answer1');
    Answer.appendChild(document.createTextNode('The Answer Is Correct'))
    }

    }

    The 'Answer1' id is a <tr id='Answer1'> which sits empty until the "Enter" button is clicked. Well, what happens is that no matter what option that I select, the "True" option automatically gets selected and the text: "The Answer Is Correct" gets written to the table row.

    hmmmmm, not sure what is going on here. If someone could help me out, I'll sure appreciate it...

    Thanks!

  2. #2
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,648
    if (rButtonT.checked == true)
    xxx: Guess Buddhist riddle: "What is the sound of one hand clapping?"
    yyy: facepalm

  3. #3
    Join Date
    Sep 2011
    Posts
    64
    Thanks, Padonak!

    Looks like I'll have to take a look at operators and get a refresher on when to use the double equals sign.

    Ha, ha .... workin good now!

    Thanks again.

  4. #4
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,648
    good to hear ))
    xxx: Guess Buddhist riddle: "What is the sound of one hand clapping?"
    yyy: facepalm

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles