redirect instead of alert

How can I modify this script. so that instead of showing an alert it redirects the user to:

mypage.asp?caseid=<%=(Cases.Fields.Item("Id").Value)%>

Script:
<script language="JavaScript">
function oneCheckboxChecked(form){
for(f=0;f<form.length;f++){
if(form[f].type !="checkbox") continue;
if(form[f].checked){
return true;
}
}
alert("Select at least one Item");{
return false;
}
}
</script>

Open in new window

LVL 1
AleksAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Big MontyWeb Ninja at largeCommented:
try:

<script language="JavaScript">
function oneCheckboxChecked(form){
for(f=0;f<form.length;f++){
if(form[f].type !="checkbox") continue;
if(form[f].checked){
return true;
}
}
window.location = 'mypage.asp?caseid=<%=(Cases.Fields.Item("Id").Value)%>';
}
</script>

Open in new window


this'll only work if your Cases recordset is still open. if you open it elsewhere, assign the value to a variable and then use the variable instead
AleksAuthor Commented:
Didn't work, the form was submitted with no selections made.
Big MontyWeb Ninja at largeCommented:
when do you want the redirect to occur? when the function oneCheckboxChecked returns false?
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

AleksAuthor Commented:
if there are no checkboxes checked the code I copied displays an alert to check at least one checkbox. Instead of this I want them to go to another page with some additional instructions.
Big MontyWeb Ninja at largeCommented:
try the code below and see if you get an alert box. if you don't, check for javascript errors in the console.

<script language="JavaScript">
function oneCheckboxChecked(form){
   for(f=0;f<form.length;f++){
      if(form[f].type !="checkbox") continue;
      if(form[f].checked){
            return true;
       }
   }
   alert('got here');
   window.location = 'mypage.asp?caseid=<%=(Cases.Fields.Item("Id").Value)%>';
}
</script>

Open in new window

AleksAuthor Commented:
Yes, it shows the alert, then the form submits instead of being re-directed to that page.
I updated the code you sent to reflect the actual page and recordset Ill use:

<script language="JavaScript">
function oneCheckboxChecked(form){
   for(f=0;f<form.length;f++){
      if(form[f].type !="checkbox") continue;
      if(form[f].checked){
            return true;
       }
   }
   alert('got here');
   window.location = 'invoice_selecterror.asp?caseid=<%=(rs_case.Fields.Item("Id").Value)%>';
}
</script>

Open in new window

Big MontyWeb Ninja at largeCommented:
and JS errors in the console?
AleksAuthor Commented:
None
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
i guess you need do a posting to a page after some javascript validation?

how the javascript function: oneCheckboxChecked was being called? can you post relevant codes here?

don't you have a form with action = "invoice_selecterror.asp?caseid=<%=(rs_case.Fields.Item("Id").Value)%>" ?
Big MontyWeb Ninja at largeCommented:
seems like it should work...lets try this:

<script language="JavaScript">
function oneCheckboxChecked(form){
   var bContinue = false;
   for(f=0;f<form.length;f++){
      if(form[f].type !="checkbox") continue;
      if(form[f].checked){
            bContinue = true;
       }
   }
   if( ! bContinue )
        window.location = 'invoice_selecterror.asp?caseid=<%=(rs_case.Fields.Item("Id").Value)%>';
   else
        return bContinue;
}
</script>

Open in new window

AleksAuthor Commented:
It activates when I try to submit the form. If no checkboxes are checked then it should redirect instead of posting the form.

Here is the checkbox code:

<input type="checkbox" name="checkbox" value="<%=(rs_charges.Fields.Item("Id").Value)%>">

Open in new window


Here is the validation script code:

<script language="JavaScript">
function oneCheckboxChecked(form){
   for(f=0;f<form.length;f++){
      if(form[f].type !="checkbox") continue;
      if(form[f].checked){
            return true;
       }
   }
   alert('got here');
   window.location = 'invoice_selecterror.asp?caseid=<%=(rs_case.Fields.Item("Id").Value)%>';
}
</script>

Open in new window


And here is the form code:

<form action="invoice_SPsave.asp?caseid=<%=(rs_case.Fields.Item("Id").Value)%>" method="post" name="form1" id="form1" onSubmit="return oneCheckboxChecked(form1)">

Open in new window


Here is my submit button, just in case:

<button type="submit" class="btn btn-primary" >Add invoice</button>

Open in new window

Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
probably you can try:

<script language="JavaScript">
function oneCheckboxChecked(form){
   for(f=0;f<form.length;f++){
      if(form[f].type !="checkbox") continue;
      if(form[f].checked){
            return true;
       }
   }   
   form.action = 'invoice_selecterror.asp?caseid=<%=(rs_case.Fields.Item("Id").Value)%>';
}
</script>

Open in new window

?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AleksAuthor Commented:
The first one worked, the second froze the screen. If you don't mind Ill share the points since Big Monty has also been helping on this one.
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
yes, no worries... yea, guess the 2nd suggestion doesn't work well so I had removed that before your latest comment. cheers
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.