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 4 of 4
  1. #1
    New to the CF scene
    Join Date
    May 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    SELECT name of FORM undefined! Why? Please help

    Could someone please help me with this seemingly simple problem. Ok...here is the deal. I am try to make a trivia quiz problem that will allow the users to enter the number of questions they want to try and the time limit. When these options are selected, then can click on the 'Start Quiz' button and take the quiz.

    I named my SELECT 'xxx' and 'yyy' for simplicty sake. My form name is simply just 'formA'. My problem lies in that fact that I can't seem to get the value the user selected. I need these value to pass to my function. But everytime I try, I keep getting the message "xxx (or yyy) undefined". I don't understand why that is. Could you look at my code and give my any feedback what I am doing wrong. Why is it undefined? This is suppose to be simple but somehow the program is not responding. Oh my God ,if anyone can help, I will appreciate it so much. sigh....here is my code:

    Code:
    <html>
    
    <head>
    <title>Online Quiz</title>
      
    <script language="javascript">
    function start_quiz()
    {
    var p1=document.formA.xxx.options[xxx.selectedIndex].value;
    var p2=document.formA.yyy.options[yyy.selectedIndex].value;
    
    parent.top_frame.global_frame.reset_quiz(p1,p2);
    window.location.href="askQuestions.html";
    }
    
    </script>
    
    </head>
    
    
    <body bgcolor="red">
    
    
    <form name="formA">
    Number of Questions 
    <br>
    <SELECT name="xxx" size="1">
    <option value=1>1
    <option value=3>3
    <option value=5>5
    </SELECT>
    
    <br><br>Time Limit<br>
    <SELECT name="yyy" size="1">
    <option value=-1>No Limit
    <option value=60>1 Minutes
    <option value=120>2 Minutes
    <option value=180>3 Minutes
    </SELECT>
    
    <br>
    <input type="button" value="start quiz" language="javascript" onclick="return start_quiz()">
    </form>
    
    
    
    </body>
    </html>

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    You refer to the select properly in the first instance but incorrectly in the next.

    var p1=document.formA.xxx.options[document.formA.xxx.selectedIndex].value;
    var p2=document.formA.yyy.options[document.formA.yyy.selectedIndex].value;

    You can pass the form reference to the function to simplify it.

    function start_quiz(f)
    {
    var p1=f.xxx.options[f.xxx.selectedIndex].value;
    var p2=f.yyy.options[f.yyy.selectedIndex].value;
    ...

    <input type="button" onclick="return start_quiz(this.form)" />
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #3
    New to the CF scene
    Join Date
    May 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up Thank you!!

    Oh my God...Glenngv, you are so right on! That solves everything. Thank you so much for helping me.

    qball

  • #4
    New Coder
    Join Date
    May 2004
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts
    DANGIT! finally something i KNOW and someone gets there before me


    lol j/k


  •  

    Posting Permissions

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