Jump to content

my Javascript if statement not functioning


blumonde

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.