<script language="JavaScript">
function validator()
if (text_form.name.value == "")
   alert("Please enter your name"); 
   return false;
return true;

<form name="text_form" method="get" action="success.html" onsubmit="validator()">
<label for="name"> Name </label>
    <input type="text" name="name"/> <br />
    <input type="submit" value="submit" />
    <input type="reset" value="reset" />


//whats wrong with my code? eventhough the validation is working, it still goes to the "success.html" helpp!! 

//thanks in advance..

Recommended Answers

All 2 Replies


onsubmit="return validator()">

yeah. i forgot the "return"// :) thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.