Jump to content

Recommended Posts

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 by Zane

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.

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

<?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

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 by Zane

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.

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 by Zane
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.