Note that there are some explanatory texts on larger screens.

plurals
  1. POmaking a custom Confirm box in javascript
    primarykey
    data
    text
    <p>I want to make a custom made confirmation box in javascipt just like the built in confirm box. the built in confirm box does not allow the code to progress unless the user selects atleast one thing. Below is my code: <strong><em>*</em>**<em>*</em>*</strong><em>HTML start</em><strong><em>*</em>**<em>*</em>*</strong></p> <pre><code>&lt;div class = "popUp confirm" style="z-index:40000;" id="confirmBlock"&gt; &lt;div id = "confirmLabel" &gt;Confirm Message&lt;/div&gt; &lt;div style ="border:0px solid red;height:44.56px;"&gt; &lt;input id="Confirm" type="button" value="Confirm" onclick = "confirmAction(1)" /&gt; &lt;input id = "CancelConfirm" type="button" value="Cancel" onclick = "confirmAction(0)" /&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p><em><strong></em>**<em>*</em>**</strong><em>HTML end</em><strong><em>*</em>**<em>*</em>*</strong></p> <p><em><strong></em>**<em>*</em>**</strong><em>Javascript start</em><strong><em>*</em>**<em>*</em>*</strong></p> <pre><code>var confirmresult = "-1"; function confirmationLoop() { alert("If this alert is preesnt it works, seems like the built in alert provides some sort of pause for other parts of code to continue to work"); if(confirmresult == "-1") confirmationLoop(); return; } function confirmAction(val) { confirmresult = val; } function checkuuu() { confirmresult = "1"; } function confirmMessage(message) { document.getElementById("confirmLabel").innerHTML= message; //var check = setTimeout(function(){confirmAction(1)},5000); confirmationLoop(); /* while(1) //using while almost does not allow any other part to run at all hence tried recursion { if(confirmresult != "-1") break; } */ document.getElementById("confirmLabel").innerHTML= "Confirm Message"; var returnVal = confirmresult; confirmresult = -1; return returnVal; } </code></pre> <p><em><strong></em>**<em>*</em>**</strong><em>Javascript end</em><strong><em>*</em>**<em>*</em>*</strong></p> <p><em><strong></em>**<em>*</em>**</strong><em>Sample code start</em><strong><em>*</em>**<em>*</em>*</strong> So this i what i expect below:</p> <pre><code>function example { var check = confirmMessage(message); //the next part of code should not execute untill i press confirm or cancel, using settimeout or settimeinterval is asynchronous and the code flow continues. i want the effect something like alert and confirm built in boxes } </code></pre> <p><em><strong></em>**<em>*</em>**</strong><em>Sample code end</em><strong><em>*</em>**<em>*</em>*</strong> </p> <p>I used loop but it keeps the thread completely occupied and does not give me a chance to press any button, which was quite obvious However recursion gives u the freedom to perform other activities. The problem even though the value of confirmResult will become 1 upon pressing confirm button, which i check through alert. the recursive loop i.e. confirmation loop does not seem read it as 1. it still continues as -1. If i put a alert in that confirmation loop the value wil be read as 1. Can anyone help me to achieve what i started out to?????? P.s.=> sorry for such a huge question!!!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload