if alert please dont submit:(

wxdqz

New Member
Dear Friends ,

I have a problem below;


When I run this script and select one or more item, script redirect me check.asp, its OK,
But when any checkboxes are checked, first its alert me and then still redirect me check.asp

I want when any checkboxes are checked,its only alert me not redirect!

Thanks


<SCRIPT language=JavaScript>
<!-- Begin
function checkrequired() {

var fields = 0
var i = 0
var empty = true
var fields = document.form1.length
var textvalue = ""

for (i = 0; i < fields ; i++) {
switch (document.form1.elements.type){
case "select-one" :
case "select-multiple" :
if (document.form1.elements.selectedIndex != -1)
{
empty = false
}
break;
case "checkbox" :
if ( document.form1.elements.checked) {
empty = false
}
break;
default :
break;
}
}

if (!empty) {
document.form1.submit();
} else {

alert("Select 1 or more item!")
}
}
// End -->
</SCRIPT>

<form name=form1 method="POST" action="check.asp">
<input type="checkbox" name="k1" value=http://www.webdeveloper.com/forum/archive/index.php/"astim" class="input">
<input type="checkbox" name="k2" value="whax" class="input">
<input onclick=checkrequired() type="image" SRC="ok.gif" border="0" name="submitit" >
</form>
 
Back
Top