SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: Question error

  1. #1
    Spam Can Kill!!! Disk-t's Avatar
    Join Date
    Jul 2001
    Location
    n/a
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question error

    This script does NOTHING when I click submit:

    <script>
    function ques1() {
    if (document.former.answer.value == "Trenton" || "trenton") { ques1c }
    else { ques1w }
    }
    function ques1c() {
    {alert("correct");ques2()}
    }
    function ques1w() {
    {alert("wrong");ques2()}
    }

    function ques2() {
    document.former.question.value="What is a?"
    if (document.former.answer.value == "num") { ques2c() }
    else { ques2w() }
    }
    function ques2c() {
    {alert("correct")}
    }
    function ques2w() {
    {alert("wrong")}
    }
    </script>

    <form name="former">
    <input type="text" name="question" onFocus="this.blur()" value="What is the capitol of NJ?">
    <input type="text" name="answer">
    <input type="button" name="button" onClick="ques1()" value="submit"> </form>

  2. #2
    SitePoint Guru Vincent Puglia's Avatar
    Join Date
    Feb 2000
    Location
    where the World once stood
    Posts
    700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi disk_t,

    I stopped looking after seeing this (so you may have more errors):

    function ques1() {
    if (document.former.answer.value == "Trenton" || "trenton"
    { ques1c }
    else { ques1w }
    }

    1) You cannot simply say
    "Trenton" || "trenton"
    each comparison must have both sides, as in:
    if ( (document.former.answer.value == "Trenton" || (document.former.answer.value == "trenton") )
    2) if you are calling a function, you need to include the parentheses:
    { ques1c() }
    else { ques1w() }

    Vinny
    Where the World Once Stood
    the blades of grass
    cut me still


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
  •