Link to home
Start Free TrialLog in
Avatar of newbie27
newbie27Flag for United Kingdom of Great Britain and Northern Ireland

asked on

create a captcha protection page

Hello Experts,
I had a script to stop spam abuse on the website to some extent, but for some reason it is not working.
Can someone please look into this.
thanks
sam
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  
<script type="text/javascript">
 window.onload=init;
 
 function init()
 {
        var val = code()
        document.getElementById('hiddenCaptcha').value=val;
        document.getElementById('visibleCaptcha').innerHTML=val;
 }
 function Random(X) {
    return Math.floor(X * (Math.random() % 1));
}
 function code() {
    var j, S = ""; 
    for (j = 0; j < 3; j++) {
        S += String.fromCharCode(65 + Random(26));
        S += String.fromCharCode(97 + Random(26));
    }
    return S;
}
    function validForm(frm){      
            var form_name = frm ;      
        var valid = true;      
        var errMsg = "";
        var emailFilter=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;            
            if(form_name.name.value==""){
                  errMsg = "Please enter your name.";
                  valid = false;
            }            
            
            if(form_name.email.value==""){
                  errMsg= errMsg + "\n Please enter your e-mail address.";
                  valid = false;
            }else if (!(emailFilter.test(form_name.email.value))) {
                  errMsg= errMsg + "\n Please enter a valid email address.";
                  valid = false;
            }      
            
            if(form_name.subjects.value==""){
                  errMsg= errMsg + "\n Please enter the subject.";
                  valid = false;
            }
            
            if(form_name.comments.value==""){
                  errMsg= errMsg + "\n Please enter your comments.";
                  valid = false;
            }
            
            if(valid == false){                  
                        alert(errMsg);
            }
                  
            
            return valid;
    }
    </script>
</head>
<body>
 <form>
<p><strong>Fields marked with an <span style="color:Red">*</span> are required.</strong></p>
</td></tr>
<table>
<tr>
<td><p>Name</p></td>
<td><input name="name" class="textfield" value="" id="Text1" type="text" /><span style="color:Red">*</span>
</td></tr>
<tr>
<td><p>Email</p></td>
<td><input name="email" class="textfield" value="" id="Text2" type="text" /><span style="color:Red">*</span>
</td></tr>
<tr>
 
<td><p>Contact number</p></td>
<td><input name="contact" class="textfield" value="" id="Text3" type="text" />
</td></tr>
<tr>
<td><p>City</p></td>
 
<td><input name="city" class="textfield" value="" id="Text4" type="text" />
</td></tr>
<tr>
<td><p>Country</p></td>
<td><select name="country" id="country" style="width:150">
<option value="UK"  selected="selected">United Kingdom</option>
<option value="AF">Afghanistan</option>
<option value="AL">Albania</option>
 
 
<option value="YU">Yugoslavia</option>
<option value="ZR">Zaire</option>
<option value="ZM">Zambia</option>
<option value="ZW">Zimbabwe</option></select>
</td></tr>
<tr>
<td><p>Subjects</p></td>
<td><input name="subjects" class="textfield" value="" id="Text5" type="text" /><span style="color:Red">*</span> 
</td></tr>
<tr>
<td><p>Your Comments</p></td>
 
<td><textarea name="comments" rows="8" cols="100" style="width: 300px; height: 100px" id="Textarea1"></textarea><span style="color:Red">*</span> 
</td></tr>
<tr>
<td colspan="2"> 
</td></tr>
<tr>
<td> </td>
<td><input name="send" value="Submit" id="Submit1" type="submit" />
                   <input value="Clear" id="Reset1" name="Reset1" type="reset" /></tbody></table></form></td></tr></tbody></table> 
<div>Code: <span  id="visibleCaptchar" style="border:1px solid black; background-color:beige;font-weight:bold;font-size:large;font-family:verdana;padding: 3px;"></span></div>
Please Enter code you see above:<input type="" name="userCaptcha" value=""/>
</form>      
 
</body>
</html>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Julian Matz
Julian Matz
Flag of Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of newbie27

ASKER

thanks