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?
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 MontySenior Web Developer / CEO of ExchangeTree.org Commented:
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
0
AleksAuthor Commented:
Didn't work, the form was submitted with no selections made.
0
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
when do you want the redirect to occur? when the function oneCheckboxChecked returns false?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

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.
0
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
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

0
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

0
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
and JS errors in the console?
0
AleksAuthor Commented:
None
0
Ryan ChongCommented:
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)%>" ?
0
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
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

0
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

0
Ryan ChongCommented:
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

?
0

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.
0
Ryan ChongCommented:
yes, no worries... yea, guess the 2nd suggestion doesn't work well so I had removed that before your latest comment. cheers
0
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.