blumonde Posted February 24, 2014 Share Posted February 24, 2014 (edited) Hello, The if statement didn't run and the confirm box didn't popup. and I don't know how to fix this after hours of debugging. Below is my code and it is simple: (when I debugging it, the variable $check does have a value of 1 in it) <?php $check = 1; ?> echo "function checkB4SaveForm()"; echo "{"; echo " var checkacct=".$check.";"; echo " if (checkacct==1)"; echo " {"; echo " var show = confirm(\"This account exists! Would you like to view it?\");"; echo " if (show==true)"; echo " {"; echo " searchAndDeleteForm();"; echo " return false;"; // show the record and cancel save transaction echo " }"; echo " else"; echo " {"; echo " return false;"; // cancel save transaction echo " }"; echo " }"; echo "}"; // end function Thanks in advance. blumonde Edited February 24, 2014 by Zane Quote Link to comment https://forums.phpfreaks.com/topic/286460-my-javascript-if-statement-not-functioning/ Share on other sites More sharing options...
Ch0cu3r Posted February 24, 2014 Share Posted February 24, 2014 How and when is the checkB4SaveForm() JavaScript function called? If you are trying to call that function from PHP then you cant. PHP and Javascript are two complete different languages, you cannot read each others variables/functions. Quote Link to comment https://forums.phpfreaks.com/topic/286460-my-javascript-if-statement-not-functioning/#findComment-1470397 Share on other sites More sharing options...
blumonde Posted February 24, 2014 Author Share Posted February 24, 2014 Hello Ch0cu3r, Thank you for your response. I call it via the submit button. The function did get called but the if statement was ignored. The reason I know this is that because I added an alert message to the function for testing and it did pop up. Regards, blumonde Quote Link to comment https://forums.phpfreaks.com/topic/286460-my-javascript-if-statement-not-functioning/#findComment-1470448 Share on other sites More sharing options...
Zane Posted February 24, 2014 Share Posted February 24, 2014 <?php $check = 1; echo <<<JSCRIIPT function checkB4SaveForm() { var checkacct={$check}; if (checkacct==1) { var show = confirm("This account exists! Would you like to view it?"); if (show) { searchAndDeleteForm(); return false; // show the record and cancel save transaction } else { return false;"; // cancel save transaction } } } // end function JSCRIPT; ?> Try this out, for the sake of syntax and good reabability Quote Link to comment https://forums.phpfreaks.com/topic/286460-my-javascript-if-statement-not-functioning/#findComment-1470452 Share on other sites More sharing options...
blumonde Posted February 24, 2014 Author Share Posted February 24, 2014 Hello Zane, Thank you for your response. It's still no effect on the conditional statement. Maybe "var checkacct={$check};" didn't transfer the value? blumonde Quote Link to comment https://forums.phpfreaks.com/topic/286460-my-javascript-if-statement-not-functioning/#findComment-1470490 Share on other sites More sharing options...
Zane Posted February 24, 2014 Share Posted February 24, 2014 (edited) While that could be possible, bluemonde. You would be the only one that can know. I didn't rewrite you entire script or anything. I simply made it more human readable. So any and all syntax errors, variable declarations, server settings, php version, apache version, operating system, etcetera... are on you. If you open the source, using view source (or Chrome's development pane), you should be able to see for sure whether or not $check went through. Edited February 24, 2014 by Zane Quote Link to comment https://forums.phpfreaks.com/topic/286460-my-javascript-if-statement-not-functioning/#findComment-1470529 Share on other sites More sharing options...
blumonde Posted February 24, 2014 Author Share Posted February 24, 2014 Yes, $check php variable does have a value of 1 in it. I saw it while using Codelobster debugger. It is "checkacct" js variable that I don't know if it gets that same value or not. Too bad there is no debugger that can debug javascript at run time. Quote Link to comment https://forums.phpfreaks.com/topic/286460-my-javascript-if-statement-not-functioning/#findComment-1470535 Share on other sites More sharing options...
Zane Posted February 25, 2014 Share Posted February 25, 2014 (edited) Maybe I'm confused, but.. Chrome comes pre-equipped with a debugger..... https://developers.google.com/chrome-developer-tools/ Using the console tab, you can easily type alert(checkacct); and press enter, and it will work. You can even call your function. Edited February 25, 2014 by Zane Quote Link to comment https://forums.phpfreaks.com/topic/286460-my-javascript-if-statement-not-functioning/#findComment-1470555 Share on other sites More sharing options...
blumonde Posted February 27, 2014 Author Share Posted February 27, 2014 Zane, My session variable is not working correctly in Drupal. I need to upgrade Drupal to the latest version. Thank you and sorry for my late response. Regards, Dominic Quote Link to comment https://forums.phpfreaks.com/topic/286460-my-javascript-if-statement-not-functioning/#findComment-1470848 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.