Results 1 to 4 of 4

Thread: Sumit button to check radios and open page in new frame?

  1. #1
    Join Date
    Feb 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Sumit button to check radios and open page in new frame?

    Hi all,

    As I'm sure you'll realize I'm quite new to all of this and have never done anything with javascript before. That said I am in a course called "Computer based instruction" where I am learning to design and develop simple programs for use in classrooms. I am having difficulty with the drill I am working on. There are four options, the student need to select the correct option. When they submit the answer they will receive feedback as to whether they sected the correct answer.

    I have it set up so that there are three frames (frames and the use of javascript are encourage for practice) "bar" on the left with navigational options, "main" in the center where the body of the drill is presented, and "feedback" along the bottom where the feedback will appear.

    My issue is that I have everything working except the form! I'm not sure how to make it so that upon clicking the submit button the feedback is presented in the "feedback" frame. This was suggested to me but isn't working, maybe I have a mistake somewhere? Or is there another way I can do this?

    Code:
    <html>
    <head>
    
    <script type="text/javascript">
    function CheckCheckbox() {
    if q1.r1.value != 'counterfeit'{
    top.frames["feedback"].location = "correct1.html";
    }
    else{
    top.frames["feedback"].location = "incorrect1.html";
    }
    </script>
    
    
     </head>
    <body>
    
    <form name="q1">
    Jenny thought the <b>fake</b> purse looked just like the real thing!
    <br>
    <br>
    <br>
    <input type="radio" name="q1" value="abhor"> abhor
    <br>
    <input type="radio" name="q1" value="magnificent"> magnificent
    <br>
    <input type="radio" name="q1" value="counterfeit"> counterfeit
    <br>
    <input type="radio" name="q1" value="placid"> placid
    <br>
    <input type="radio" name="q1" value="abrasive">abrasive
    <br>
    
    <input type="button" name="Submit" value="Submit" onclick="CheckCheckbox()">
    
    </form>
    
    
    
    
    
    </body>
    </html>
    If anyone could help that would be great!!

    Thanks so much.
    If you need more information please let me know.

  2. #2
    Join Date
    Aug 2008
    Location
    karanganyar, solo, indonesia
    Posts
    161
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default

    *you missed the '(' and '}'
    *Element referenced by ID/NAME in the global scope. Use W3C standard document.getElementById() instead. use getElementById instead of q1.r1.value
    *your form name is same as radio name, don't do that

    below are correct one

    Code:
    <html>
    <head>
    
    <script type="text/javascript">
    
    
    function getRadio(f, n){
     f = document.forms[f].elements;
     for (var i = f.length - 1; i > -1; --i)
      if(f[i].name == n && f[i].checked)
       return f[i].value;
     return 'undefined';
    }
    
    function CheckCheckbox() {
    if (getRadio('q1', 'r1')!= 'counterfeit'){
    top.frames["feedback"].location = "correct1.html";
    //alert('true');
    }
    else{
    top.frames["feedback"].location = "incorrect1.html";
    //alert('wrong');
    }
    }
    </script>
    
    
     </head>
    <body>
    
    <form name="q1">
    Jenny thought the <b>fake</b> purse looked just like the real thing!
    <br>
    <br>
    <br>
    <input type="radio"  name="r1" value="abhor"> abhor
    <br>
    <input type="radio"  name="r1" value="magnificent"> magnificent
    <br>
    <input type="radio" name="r1" value="counterfeit"> counterfeit
    <br>
    <input type="radio"  name="r1" value="placid"> placid
    <br>
    <input type="radio"  name="r1" value="abrasive">abrasive
    <br>
    
    <input type="button" name="Submit" value="Submit" onclick="CheckCheckbox()">
    
    </form>
    
    
    
    
    
    </body>
    </html>
    Last edited by smansakra; 02-13-2009 at 04:32 AM.
    ///////////////////////////////////////////////////
    ///// http://www.mediatutorial.web.id
    ///////////////////////////////////////////////////

  3. #3
    Join Date
    Feb 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    YES!!! Thank you soooo much! it works! I have been trying to figure this out for weeks. (Which I know is kinda sad since it's really not that complicated..)

    Thanks a million, I can't wait to finish the drill now!

  4. #4
    Join Date
    Aug 2008
    Location
    karanganyar, solo, indonesia
    Posts
    161
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default you're wellcome

    you're wellcome
    ///////////////////////////////////////////////////
    ///// http://www.mediatutorial.web.id
    ///////////////////////////////////////////////////

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
  •