html - Javascript Prompt Cancel Button not "Canceling" -
i've noticed when have user enter text through prompt window, prompt return null , continue moving on code. want cancel button says , cancel. i've tried several if statements, including:
var x= prompt("please enter number <x>: (<x> + <y>)"); if (x === null) { return; } var y= prompt("please enter number <y>: (<x> + <y>)"); if (x === null) { return; } eval ("x=x; y=y; alert(+x + + y)"); }; the above not change anything
var x= prompt("please enter number <x>: (<x> + <y>)"); if (verifyinput(false)) { return; } var y= prompt("please enter number <y>: (<x> + <y>)"); if (verifyinput(false)) { return; } eval ("x=x; y=y; alert(+x + + y)"); }; and 1 makes both ok , cancel buttons return false, , code not continue when ok pressed.
is code affect cancel button stops script continuing? thanks!
i new website pardon me if didn't make myself terribly clear :)
you're checking equality null when prompt returns string; won't work. instead, should condition:
if ( x === "" ) { / ... / } here you're checking empty string. moreover, eval statement doesn't anything, can execute same code without it:
alert( +x + +y );
Comments
Post a Comment