Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: What have I done wrong?

  1. #1
    Junior Member
    Join Date
    Sep 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default What have I done wrong?

    <html>
    <head>
    <title>Exam entry</title>
    <script language="javascript" type="text/javascript"> function validateForm() {
    var result = true; var msg="";

    if (document.ExamEntry.name.value=="") { msg+="You must enter your name \n"; document.ExamEntry.name.focus();
    document.getElementById('name').style.color="red"; result = false;
    }


    if (document.ExamEntry.subject.value=="") { msg+="You must enter the subject \n"; document.ExamEntry.subject.focus();
    document.getElementById('subject').style.color="re d"; result = false;
    }

    if (document.ExamEntry.subject.value=="") { msg+="You must enter your examination number \n"; document.ExamEntry.subject.focus();
    document.getElementById('number').style.color="red "; result = false;
    }

    if(msg==""){ return result;
    }

    {
    alert(msg) return result;
    }
    }

    </script>
    </head>

    <body>
    <h1>Exam Entry Form</h1>
    <form name="ExamEntry" method="post" action="success.html">
    <table width="50%" border="0">
    <tr>
    <td id="name">Name</td>
    <td><input type="text" name="name" /></td>
    </tr>
    <tr>
    <td id="subject">Subject</td>
    <td><input type="text" name="subject" /></td>
    </tr>
    <tr>
    <td id="number">Examination Number</td>
    <td><input type="number" name="number" /></td>
    </tr>

    <tr>
    <td><input type="submit" name="Submit" value="Submit" onclick="return validateForm();" /></td>
    <td><input type="reset" name="Reset" value="Reset" /></td>
    </tr>

    </table>
    </form>
    </body>
    </html>
    I'm trying to get a message up if the box is left blank... What have I done wrong? TTmTT


  2. #2
    Junior Member
    Join Date
    Sep 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help Wanted!!!

    Ok, so a change of question... Why wont it validate? I mean there isn't anything wrong with it, right?
    <html>
    <head>
    <title>Exam entry</title>
    <script language="javascript" type="text/javascript"> function validateForm() {
    var result = true; var msg="";

    if (document.ExamEntry.name.value=="") { msg+="You must enter your name \n"; document.ExamEntry.name.focus();
    document.getElementById('name').style.color="red"; result = false;
    }


    if (document.ExamEntry.subject.value=="") { msg+="You must enter the subject \n"; document.ExamEntry.subject.focus();
    document.getElementById('subject').style.color="re d"; result = false;
    }

    if (document.ExamEntry.subject.value=="") { msg+="You must enter your examination number \n"; document.ExamEntry.subject.focus();
    document.getElementById('number').style.color="red "; result = false;
    }

    if(msg==""){ return result;
    }

    {
    alert(msg) return result;
    }
    }

    </script>
    </head>

    <body>
    <h1>Exam Entry Form</h1>
    <form name="ExamEntry" method="post" action="success.html">
    <table width="50%" border="0">
    <tr>
    <td id="name">Name</td>
    <td><input type="text" name="name" /></td>
    </tr>
    <tr>
    <td id="subject">Subject</td>
    <td><input type="text" name="subject" /></td>
    </tr>
    <tr>
    <td id="number">Examination Number</td>
    <td><input type="number" name="number" /></td>
    </tr>

    <tr>
    <td><input type="submit" name="Submit" value="Submit" onclick="return validateForm();" /></td>
    <td><input type="reset" name="Reset" value="Reset" /></td>
    </tr>

    </table>
    </form>
    </body>
    </html>
    So frustrating... If anyone could help that would be great!
    OH! Also, if you could tell me how it's only accepted if there is 4 digits in the Examination Number box...? Heheh

  3. #3
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 697 Times in 679 Posts

    Default Re: What have I done wrong?

    Thread moved.

    JavaScript != Java.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,475
    Thanks
    53
    Thanked 2,405 Times in 2,358 Posts

    Default Re: Help Wanted!!!

    Moved. Not a java question.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Replies: 4
    Last Post: March 6th, 2014, 05:14 PM
  2. [SOLVED] What am i doing wrong?
    By Inguana in forum What's Wrong With My Code?
    Replies: 6
    Last Post: November 30th, 2013, 11:13 AM
  3. what wrong with this??
    By sephskie in forum What's Wrong With My Code?
    Replies: 3
    Last Post: January 14th, 2012, 07:50 PM
  4. Not sure what is wrong
    By dremn2004 in forum What's Wrong With My Code?
    Replies: 10
    Last Post: June 18th, 2011, 10:49 AM
  5. Not sure what is wrong with this
    By jwb4291 in forum What's Wrong With My Code?
    Replies: 7
    Last Post: June 29th, 2010, 02:23 PM