Link to home
Start Free TrialLog in
Avatar of Aleks
AleksFlag for United States of America

asked on

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

SOLUTION
Avatar of Big Monty
Big Monty
Flag of United States of America 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 Aleks

ASKER

Didn't work, the form was submitted with no selections made.
when do you want the redirect to occur? when the function oneCheckboxChecked returns false?
Avatar of Aleks

ASKER

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.
SOLUTION
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 Aleks

ASKER

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

and JS errors in the console?
Avatar of Aleks

ASKER

None
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)%>" ?
SOLUTION
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 Aleks

ASKER

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

ASKER CERTIFIED SOLUTION
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 Aleks

ASKER

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