Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript Confirm

Status
Not open for further replies.

tewari68

Programmer
Jan 25, 2005
87
US
Hi,
I have a php form with two sets of radio buttons to undelete or to purge and one submit button to do the required action.
I want to add a javascript confirm statement only when the purge radio button is selected, the user can select either a single file to purge or multiple files to purge and when the user clicks on the submit button I want a javascript confirm statement to confirm purging the files.
Right now I have put the confirm onclick event when the submit button is clicked so the confirm statement window pops up even if only undelete radio buttons are selected.
However I just want the confirm statement when the purge buttons are selected.
Don't know much javascript, appreciate any help.

Thanks,
Mohit
 
How about showing your form and JS code so we can see what we're working with?

Lee
 
Use a function as the event handler instead of a single line of code.

Probably you have something like this now
Code:
<html>
...
<input type="submit" onclick="confirm('Are you sure?');">
...
</html>

So you need to do this
Code:
<html>
...
<input type="submit" onclick="doConfirm();">
...
<script>
function doConfirm(){
   
   var the_right_buttons_are_checked = false;
   //logic to check which buttons are selected.
   //  setting the variable true if we need to confirm.
   your code goes here
   
   if ( the_right_buttons_are_checked ) {
     if ( confirm("Are you sure?") ) {
        //They clicked OK so submit the form.
        document.myForm.submit();
     }
   
   } else {
   
     //No need to confirm so submit the form.
     document.myForm.submit();
   }
}
</script>
</html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top