?
Solved

Submit form from a checkbox with a confirm message using JavaScript/jQuery?

Posted on 2013-05-29
5
Medium Priority
?
382 Views
Last Modified: 2013-06-03
Is there a way to submit a form from a checkbox with a confirm message using JavaScript/jQuery?
I basically want to display a message saying something like "Are you sure you want to lock this form?" prior to be submitted.

<form action="<?php echo $editFormAction; ?>" method="POST"  enctype="multipart/form-data" name="upd_application" id="upd_application">

<input name="row_view_appl[locked]" type="checkbox" id="locked"  value="1" >

Open in new window

0
Comment
Question by:sabecs
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 9

Expert Comment

by:TvMpt
ID: 39204020
$('#upd_application').click( function(e){
  $('#locked').val( e.value ); // capture on check or uncheck
  $(this).closest('form').submit();
});

Open in new window


Instead click you can use change too...
0
 

Author Comment

by:sabecs
ID: 39204053
Thanks  TvMpt, that's great but how can we add a confirm message saying something like "Are you sure you want to lock this form?" prior to be submitted.?
0
 
LVL 9

Expert Comment

by:TvMpt
ID: 39204064
if (confirm("Are you sure you want to lock this form?"))
{
   $(this).closest('form').submit();
}
0
 

Author Comment

by:sabecs
ID: 39204169
Thanks again, this is what I have so far but if they click cancel the box stays ticked?
If they un tick it the message pops up again?

is there an easy way for it to only come up if the tick the box and also un tick the box if they select cancel on the confirm message?


$('#locked').click( function(e){
       if (confirm("Are you sure you want to lock this form?")){
         $(this).closest('form').submit();
}
});



<input name="locked" type="checkbox" id="locked"  value="Y"/>
0
 
LVL 9

Accepted Solution

by:
TvMpt earned 2000 total points
ID: 39204300
You have the  e.value to make the logic
compare if is ticked or not and if not just return and do nothing
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question