0

im able to insert data in mysql and redirect to my index page. but my confirmation alert box wont pop-up after clicking my button/ submit form, whats the problem? :(


php/javascript page(seatplan_occupied.php):

<script>
   function formOccupied()
   {
   document.getElementByName("formOccupied").innerHTML;

    if (confirm("Are you sure you want to confirm your purchase?") == true)
    {
        alert("Yeay! You bought ticket/s");
        <?php
        include("databaseconnect.php");

        if (mysql_query("UPDATE tblseatchart SET seatSTATUS='Occupied' WHERE seatSTATUS='Selected'"));

        include("index.php");
        ?>
    }

    else
    {
       alert("Owh No! You Cancelled to confirm... Whats wrong?");
    }

}
</script>



html page:

<form name = "formOccupied" method="post" onSubmit="occupied()" action="seatplan_occupied.php">
<input name = "btnSubmit" type = "submit" value="CONFIRM">
</form>

1 Answers1

0

There seem to be two problems:

  1. You created a function called formOccupied but are trying to call a function called occupied.
  2. That function appears to be defined in seatplan_occupied.php but you are trying to call it using a form in index.html. JavaScript runs in the current page, not the next one.

Other things to note:

  • PHP inside a JavaScript if statement will run regardless
  • You haven't done anything to stop the form submitting if the user selects Cancel on the confirm
  • There is no getElementByName method, its getElementsByName and it returns a NodeList, not an element, but you'd be better off using getElementById (and using id instead of the obsolete name on the form) or, event better, using addEventListener combined with the this keyword instead of the onsubmit attribute
Community
  • 1
  • 1
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • could you show me how its done? im not a pro in programming. im not sure how to use the addEventListener with the this keyword. – user3811657 Aug 09 '14 at 18:42