hey,i jave this code. how to check the textbox (mname) to accept only letters?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
<link rel="stylesheet" type="text/css" href="mystyle.css" /> <!--- call my style -->
<title>Home page -  MidermFaill2015 - Andreas Petrou</title> <!--- title of page -->
<!--Andreas Petrou 8600-->

<script type="text/javascript">
<!--Script for check is empty-cells-->
function val(){
    var str = document.forms["form1"]["mname"].value;
    if (str == null || str == "") {
        alert("Please enter your NAME for go to the next page:");
        return false;


<!--Script for check is empty-cells-->
function surname(){

var sts = document.forms["form1"]["sname"].value;
    if (sts == null || sts == "") {
    alert("Please enter your SURNAME for go to the next page:")
    return false;

<!--Script for check is empty-cells-->
function secword(){

var stf = document.forms["form1"]["sword"].value;
    if (stf == null || stf == "") {
    alert("Please enter your SECRET WORD for go to the next page:")
    return false;

<!-- check the secret word---------->
function ch(){
var rts= "abc1"// the true secret
var stx = document.forms["form1"]["sword"].value;
 if (stx == rts) // check the secret true
  alert("your SECRET is true") // the message is true the secret word
  return true;

alert("Please try another SECRET word") // the message is flase the secret word
stx == null;

return false;


<!---------- clear the form ---------- >
function clearLs() {
form1.reset(); // Clear all data in form




 <!--Main page-->
 <p>Welocome to first page</p>
 <p>Click to the enter side button to continue</p>
 <p>***Please fill the textboxs***</p>

<!--Form to netxt and functon call-->
<form name="form1" action="step2.php" onsubmit="return val(),surname(),secword(),ch()" method="post" >
Name:        <td><input type="text" name="mname" size="20" maxlength="12" value="" /> <br/></td>  <!--- Name textbox-->
Surname:     <td><input type="text" name="sname" size="20" maxlength="12" value="" /> <br/></td>  <!--- Surname textbox-->
Secret Word: <td><input type="text" name="sword" size="20" value="" /> <br/></td>  <!--- Secret word  textbox-->
  <!--Button to next-->
<input type ="submit"  value="Enter Side"  />
<input type="button" value="Clear" onClick="clearLs()"/> <!---- clear all date in form -->


Recommended Answers

All 4 Replies

This is not Java code, this is JavaScript code. If you think they are the same, it's a bit as saying a Car is the same as a Carpet

Anyway, have you tried applying a regex validation?

meaning ... what, exactly? what have you tried, and what is going wrong?
your description of the problem is pretty vague.

Could you show us exactly what you try, where (and when) during the flow it goes wrong, and in which way it goes wrong?

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.