funbinod Posted June 1, 2014 Share Posted June 1, 2014 the following script to ask for confirmation before submitting a form is not working while clicking yes. please guide me find the error... <script>$(function () { 'use strict'; function confirmDialog(title, message, success) { var confirmdialog = $('<div></div>').appendTo('body') .html('<div><h6>' + message + '</h6></div>') .dialog({ modal: true, title: title, zIndex: 10000, autoOpen: false, width: 'auto', resizable: false, buttons: { Yes: function () { success(); $(this).dialog("close"); }, No: function () { $(this).dialog("close"); } }, close: function() { $(this).remove(); } }); return confirmdialog.dialog("open"); } $('form').on('submit', function (e) { e.preventDefault(); var form = this; confirmDialog('Confirm', 'Are you sure?', function () { form.submit(); }); });});</script> Link to comment Share on other sites More sharing options...
Ingolme Posted June 1, 2014 Share Posted June 1, 2014 I think the line breaks in this part are causing each line to be interpretted as a separate line of code: confirmdialog = $('<div></div>').appendTo('body').html('<div><h6>' + message + '</h6></div>').dialog({ Try putting them all one one line. Also, check the browser's error console anytime your code isn't working. Link to comment Share on other sites More sharing options...
funbinod Posted June 1, 2014 Author Share Posted June 1, 2014 i did that. but the problem remained same... Link to comment Share on other sites More sharing options...
Ingolme Posted June 1, 2014 Share Posted June 1, 2014 So what does the Javascript console say? Are there any error messages? Link to comment Share on other sites More sharing options...
funbinod Posted June 2, 2014 Author Share Posted June 2, 2014 no! there is nothing! Link to comment Share on other sites More sharing options...
Ingolme Posted June 2, 2014 Share Posted June 2, 2014 Well, time to start looking for problems: Find out what's happening when the "Yes" button is clicked by sending data to the console: Yes: function () {console.log("The function is running", success);success();$(this).dialog("close");}, Link to comment Share on other sites More sharing options...
funbinod Posted June 2, 2014 Author Share Posted June 2, 2014 The function is running function () {form.submit(); }Uncaught TypeError: object is not a function Link to comment Share on other sites More sharing options...
Ingolme Posted June 2, 2014 Share Posted June 2, 2014 Hmm, that's odd. Well, you're getting an error message. On what line is the Uncaught TypeError and what code is on that line? Link to comment Share on other sites More sharing options...
funbinod Posted June 3, 2014 Author Share Posted June 3, 2014 (edited) on line 87 buttons: { Yes: function () { console.log("The function is running", success); success(); $(this).dialog("close"); }, No: function () { $(this).dialog("close"); } }, close: function() { $(this).remove(); // line 87 Edited June 3, 2014 by funbinod Link to comment Share on other sites More sharing options...
Ingolme Posted June 3, 2014 Share Posted June 3, 2014 I would check to see what value this has, then. If this isn't referring to an element then there will be a problem. Can you see how this process is going yet? If at every step of the debugging process you continue asking me what to do next you're not going to learn how to do it yourself. Try to figure out what to do next, which I don't know myself until we find out what value this has. Link to comment Share on other sites More sharing options...
funbinod Posted June 3, 2014 Author Share Posted June 3, 2014 u r right. i appreciate ur guidance so far and this suggestion. but since i'm beginner i know less. if u guide me through the process it would itself make me do it myself next time (on other relative processes also). so i expect ur kindly appearance till this problem is solved. i think this is what u expected to know for the value assigned for this. (or i'm not sure)... $('form').on('submit', function (e) { e.preventDefault(); var form = this; confirmDialog('Confirm', 'Are you sure?', function () { form.submit(); }); }); Link to comment Share on other sites More sharing options...
Ingolme Posted June 3, 2014 Share Posted June 3, 2014 The error occurs on line 87, so naturally the "this" I'm looking for is the one on line 87. close: function() { console.log(this); // I need to know what "this" is $(this).remove().} Link to comment Share on other sites More sharing options...
funbinod Posted June 3, 2014 Author Share Posted June 3, 2014 its logging nothing... just showing "Uncaught TypeError................" Link to comment Share on other sites More sharing options...
Ingolme Posted June 3, 2014 Share Posted June 3, 2014 On what line is that error now? Link to comment Share on other sites More sharing options...
funbinod Posted June 3, 2014 Author Share Posted June 3, 2014 its on same line as before ( line 87 ) Link to comment Share on other sites More sharing options...
Ingolme Posted June 3, 2014 Share Posted June 3, 2014 It has to be logging something. There's something you're not doing right. Make sure you're running the right code, and that previous code hasn't been cached by the browser. Link to comment Share on other sites More sharing options...
funbinod Posted June 3, 2014 Author Share Posted June 3, 2014 i dunno what i'm not doing right. i also expect it to log something. i also cleared the browser cache but it doesn't log anything. it just shows the typeerror on line 87... Link to comment Share on other sites More sharing options...
Ingolme Posted June 4, 2014 Share Posted June 4, 2014 What does your current code look like? Link to comment Share on other sites More sharing options...
funbinod Posted June 4, 2014 Author Share Posted June 4, 2014 <script>$(function () { 'use strict'; function confirmDialog(title, message, success) { var confirmdialog = $('<div></div>').appendTo('body').html('<div><h4>' + message + '</h4></div>').dialog ({ modal: true, title: title, zIndex: 10000, autoOpen: false, width: 'auto', resizable: false, buttons: { Yes: function () { success(); $(this).dialog("close"); }, No: function () { $(this).dialog("close"); } }, close: function() { console.log(this); $(this).remove(); } }); return confirmdialog.dialog("open"); } $('form').on('submit', function (e) { e.preventDefault(); var form = this; confirmDialog('Confirm', 'Are you sure?', function () {form.submit(); }); });});</script> Link to comment Share on other sites More sharing options...
Ingolme Posted June 4, 2014 Share Posted June 4, 2014 Line 87 should have console.log(this); which has no reason to trigger any errors. The error should be occurring on line 88, meaning that the value of "this" should be visible in the javascript console. This is getting tedious. Can you show an online sample page? Link to comment Share on other sites More sharing options...
funbinod Posted June 4, 2014 Author Share Posted June 4, 2014 (edited) ok! u can access the page on http://103.28.84.9/ac/acregister.php but if u find it to be online offline, please wait till i get online. coz this is the ip from my router (since i'm using public ip, my localhost can be accessed through this ip). Edited June 4, 2014 by funbinod Link to comment Share on other sites More sharing options...
Ingolme Posted June 4, 2014 Share Posted June 4, 2014 The page takes too long to load, though I was capable of seeing the source code for a moment. There could be many reasons why it's not working, I would start by making sure the HTML is valid: http://validator.w3.org/#validate_by_input Drop the HTML transitional doctype and use HTML 5. You pointed to the wrong line. Line 87 is this one: confirmDialog('Confirm', 'Are you sure?', function () { form.submit();}); So put the console.log() there: console.log(form);form.submit(); Link to comment Share on other sites More sharing options...
funbinod Posted June 4, 2014 Author Share Posted June 4, 2014 upppsssss! sorry! now it says undefined Link to comment Share on other sites More sharing options...
Ingolme Posted June 4, 2014 Share Posted June 4, 2014 That means that the variable "form" isn't set. That's probably a scope issue. Give the <form> element an ID attribute and use getElementById() to access it. Link to comment Share on other sites More sharing options...
funbinod Posted June 5, 2014 Author Share Posted June 5, 2014 (edited) its still the same issue document.getElementById('acregister').submit();document.getElementById('acregister').click(); $('#acregister').submit();$('#acregister').click(); both methods give same result... :'( Edited June 5, 2014 by funbinod Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now