+ 4

JavaScript: How can I make my code that if no input of user (prompt) is inserted, the code will stop?

https://code.sololearn.com/WgB298ZxYunF/?ref=app

17th May 2017, 10:46 AM
Iwan
Iwan - avatar
6 Answers
0
set this code at <head> , script at head is executed before the body page is loaded , you can insert it also at the body befor the html section you don't want it to be loaded. <script type='text/javascript'> var x = prompt("enter name"); if(x===""){ window.stop(); } </script>
17th May 2017, 12:21 PM
Loai Hazima
Loai Hazima - avatar
+ 7
var s = prompt("Enter Value:"); if s !== ""){ document.write(" <h1> . </h1>"); }
17th May 2017, 11:34 AM
Art456
Art456 - avatar
+ 4
http://stackoverflow.com/questions/12864582/javascript-prompt-cancel-button-to-terminate-the-function If the user just presses ok, an empty string is returned I guess. So you could check for that
17th May 2017, 11:06 AM
Nihar Raote
Nihar Raote - avatar
+ 2
var s = prompt("Enter value:"); if ( s!== "") { // Get input s }
17th May 2017, 11:14 AM
CalviŐ˛
CalviŐ˛ - avatar
+ 2
Try this.. function func() { var s = prompt ("Please enter your bank code: \n (Just for fun,^_^) "); if(s!=undefined) confirm (" Thanks for purchasing! \n------------------------------------- \n Apple Retail Store Seattle \n Confirm purchase: \n Macbook Air 13.3 inch 128GB \n $ 15000 "); }
17th May 2017, 11:40 AM
CalviŐ˛
CalviŐ˛ - avatar
+ 1
I mean not the current​ prompt, but the whole html, JavaScript and CSS code
17th May 2017, 11:32 AM
Iwan
Iwan - avatar