-4

When my user has completed a booking form I want the form to ask them whether they are sure about booking. I think the best way to do this is with a confirm function? But if its not please do tell.

If it is with a confirm function, how do I get the confirm function to reference the values they have set in the form? Below is the form:

     <form class="submit_date" method="post" action="insert.php" id="submit_date">              
    <p>Date: <input type="text" name="datepicker" id="datepicker" required></p>
    <input type="radio" name="bookperiod" id="bookperiod" value="1" required/>1<br>
    <input type="radio" name="bookperiod" id="bookperiod" value="2" required/>2<br>
    <input type="radio" name="bookperiod" id="bookperiod" value="3" required/>3<br>    
    <input type="radio" name="bookperiod" id="bookperiod" value="4" required/>4<br>    
    <input type="radio" name="bookperiod" id="bookperiod" value="5" required/>5<br>
    <select class="dropdown" id="bookroom" name="bookroom" required>
    <option selected disabled hidden value=''></option>
    <?php
    for ($x=0; $x<sizeof($rooms_array); $x++)
     {           
     echo "<option value='$rooms_array[$x]'>".$rooms_array[$x]."</option>";
     }
     ?> 
           </select>
    <input  class="submit_btn" value="Submit" type="submit" name="Submit";/>      
        </form>

I need the confirm function to say something like:

"Are you sure you want to book $rooms_array on bookperiod at submit_date"

I STRESS I KNOW HOW TO MAKE A CONFIRM FUNCTION , BUT HOW DO I MAKE THE CONFIRM FUNCTION ECHO MY PHP VARIABLES AS IT IS A JAVASCRIPT FUNCTION

  • You say you "think the best way to do this is with a confirm function", so why not give it a shot first? – zxqx Apr 28 '14 at 17:53
  • @zakang Because I dont know how to place my PHP variables into a confirm, thats what my question is asking. NOT how to make a confirm – user3568216 Apr 28 '14 at 18:31

2 Answers2

0

do this

     <input  class="submit_btn" value="Submit" type="submit" onclick="checkconfirm()"> name="Submit";/>  
      <script type="text/javascript">
    function check confirm() {
      var result= confirm('are you sure?');
if (result==true) {
    //Logic to delete the item
}else{


   //user pressed cancel. Do nothing
    }
}
</script>
hellosheikh
  • 2,929
  • 8
  • 49
  • 115
0
<script type="text/javascript" language="JavaScript">
function AskAndSubmit(t)
{
  var answer = confirm("Are you sure you want to do this?");
  if (answer)
  {
     t.form.submit();
  }
}
</script>

<form action="Tests/Test.html" method="GET" name="subscriberAddForm">
<input type="hidden" name="locationId" value="2721"/>
<input type="text" name="text" value="3.1415926535897732384"/>
<input type="button" name="Confirm" value="Submit this form" onclick="AskAndSubmit(this)"/>
</form>

Via: Display confirmation popup with JavaScript upon clicking on a link

Community
  • 1
  • 1