What's new

Welcome to the forum 👋, Visitor

To access the forum content and all our services, you must register or log in to the forum. Becoming a member of the forum is completely free.

Problem with my validation script!

curtm8

Junior Member
Joined
Jun 17, 2013
Messages
1
Reaction score
0
HTML Coins
0
Hello gentlemen,

I have a problem with my GCSE coursework and I cant quite pinpoint the problem and was wondering if you guys could help me!:confused::rolleyes::cool::eek:
Here is my code!
Code:
<head>

<title>Exam entry</title>

<script language="javascript" type="text/javascript">

function validateForm() {
	
var result = true;
var msg="";
var entry = document.querySelector('input[name="grade"]:checked').value;
var answer = confirm("You have chosen" + " " + entry + ", are you sure?");
var DG = Working;
	DG+= '1';
	if (document.ExamEntry.name.value=="") {
		msg+="You must enter your name \n";
		document.ExamEntry.name.focus();
		document.getElementById('name').style.color="red";
		result = false;
		DG+= '2';
	}
	
	if (document.ExamEntry.subject.value=="") {
		msg+="You must enter the subject \n";
		document.ExamEntry.subject.focus();
		document.getElementById('subject').style.color="red";
		result = false;
		DG+= '3';
	}
	
	if(answer){
		alert("You have confirmed that you chosen" + " " + entry + "!");
		DG+= '4';
	}
	else{
		alert("Please change to appropriate entry!");
		result = false;
		DG+= '5';
	}
	if(document.ExamEntry.examno.value.length !== 4) { 
		msg+="You must enter a four digit examination number \n";
		document.ExamEntry.examno.focus();
		document.getElementById('examno').style.color="red";
		result = false;
		DG+= '6';
	}
		
	if(msg==""){
		return result;
			}
	{
	alert(msg);
	DG+= '7';
	return result;
	alert(DG);
	}
	}

</script>
</head>

<body>
<h6 id="Debug">Working...</h6>
<h1>Exam Entry Form</h1>
<blockquote>
  <blockquote>
    <form name="ExamEntry" method="post" action="success.html">
    <table width="52%" 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="examno">Examination Number</td>
          <td><input name="examno" type="text" maxlength="4" /></td>
          
        </tr>
        
        <tr>
		<td id="grade">Level of Entry</td>
		<td>
        <input type="radio" name="grade" id="GCSE" value="GCSE" checked="checked"/>GCSE
		<input type="radio" name="grade" id="AS" value="AS"/>AS
        <input type="radio" name="grade" id="A2" value="A2"/>A2</td>
        </tr>
        
        <tr>
          
          <td></td>
          <td><input align="right" type="submit" name="Submit" value="Submit" onClick="return validateForm();" /><input align="right" type="reset" name="Reset" value="Reset" /></td>
          
        </tr>
        
      </table>
    </form>
  </blockquote>
</blockquote>
</body>
 
I would suggest using this instead. Use an input button instead of a submit button.

<input align="right" type="button" name="Submit" value="Submit" onClick="submitForm()" />

<script>
function submitForm(){
if(validateForm()){
document.getElementById("ExamEntry").submit();
}
}
</script
 
You can also try out by adding - "onSubmit=validateForm();" on the <form....> line after the action property. I think that would help too without changing much on your code.
 

Theme customization system

You can customize some areas of the forum theme from this menu.

  • Wide/Narrow view

    You can control a structure that you can use to use your theme wide or narrow.

    Grid view forum list

    You can control the layout of the forum list in a grid or ordinary listing style structure.

    Picture grid mode

    You can control the structure where you can open/close images in the grid forum list.

    Close sidebar

    You can get rid of the crowded view in the forum by closing the sidebar.

    Fixed sidebar

    You can make it more useful and easier to access by pinning the sidebar.

    Close radius

    You can use the radius at the corners of the blocks according to your taste by closing/opening it.

  • Choose the color combination that reflects your taste
    Background images
    Color gradient backgrounds
Back