...

View Full Version : Problom With Validation Script



JsHelp
08-25-2007, 09:30 PM
Hi guys, i have a little problom with Check Function :)

*********************************************************

<form method="POST" id="SearchBox" name="SearchBox" action="Search.php" onsubmit="return Scheck()">
<input type="text" name="Sname" size="20" dir="rtl" style="width:100%; height:21px;" class="textbox" onkeydown="if ((event.which && event.which == 13) || (event.keyCode && event.keyCode == 13)) {document.SearchBox.Search.click(); return false; } else return true;">
<input type="image" src="Images/MainSite/SearchButton.jpg" name="Search" value="Submit" width="66" height="24">
</form>

This was the form... now look.. onsubmit = Scheck();
Scheck is a function that checks if the field is empty or not.

here is the js for Scheck:

<script>
function Scheck() {
if (SearchBox.Sname.value=='') {
alert("Search Box Is Empty!!!");
SearchBox.Sname.focus();
return false;
}
SearchBox.submit();
}
</script>




Now.. what should be going on is this:
someone write down some **** inside the textbox.. if he press Enter button (value = 13) -> the submit button inside the form is clicked (good!). when it's clicked = form is submit. the form then sends it to Scheck() (js function)
because onsubmit = scheck()...

but inside the site, when you press Enter key and the input text field is empty, you get some kind of error related
to the submit button (document.SearchBox.Search is empty or not NULL).

http://www.ForEver.co.il/V1/

Hope you'll know better then i do :)

mcjwb
08-26-2007, 07:37 PM
Do you really need all that code in the onkeypress event handler?

Whether you click the submit button or press enter the onsubmit event handler will be called so I don't see why you need to do anything different if the enter key is pressed.

Also you should change this line:

SearchBox.submit();
to simply

return true;
in your Scheck function.

rwedge
08-26-2007, 08:32 PM
Give this a try:
<script type="text/javascript">
function Scheck(frm, field) {
if (frm[field].value === '') {
alert('Search Box Is Empty!!!');
frm[field].focus();
return false;
} else {
return true;
}
}
document.onkeydown = function(evt) {
var evt = (evt || event) || null;
var node = (evt.target || evt.srcElement) || null;
if ((evt.keyCode == 13) && (node.type == "text")) {
return false;
}
}
</script>

<form method="POST" id="SearchBox" name="SearchBox" action="Search.php" onsubmit="return Scheck(this,'Sname')">
<input type="text" name="Sname" size="20" dir="rtl" style="width:100%; height:21px;" class="textbox">
<input type="image" src="Images/MainSite/SearchButton.jpg" name="Search" value="Submit" width="66" height="24">
</form>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum