+ 4
JavaScript: How can I make my code that if no input of user (prompt) is inserted, the code will stop?
6 ответов
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>
+ 7
var s = prompt("Enter Value:");
if s !== ""){
document.write(" <h1> . </h1>");
}
+ 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
+ 2
var s = prompt("Enter value:");
if ( s!== "") {
// Get input s
}
+ 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 ");
}
+ 1
I mean not the current prompt, but the whole html, JavaScript and CSS code