These are used when you want the user to enter text into a dialog box. They are like AppleScript dialogs with 'default answer...' They display "OK" and "Cancel" buttons and a text entry box. "OK" returns the text that was entered. "Cancel" returns the value null. The null value is somewhat like the empty value in AppleScript:<head>
<script type="text/javascript">
function screenNamePrompt()
{
var screenName=prompt("Enter your screen name","MacUser");
if (screenName!=null && screenName!="")
{
alert("Your screen name is " + screenName + " !");
}
else
alert("Don't you have a screen name?");
}
</script>
</head>The Statement 'var screenName=prompt("Enter your screen name:","MacUser");' tells JavaScript that you are requesting a dialog with the text prompt: 'Enter your screen name:' and the default entry text 'MacUser'
There are a few things to note here. First, the line 'if (screenName!=null && screenName!="")':
The symbol '!' means not or not equal to. So, in this case, if the user clicks the cancel button or enters no text at all, the first conditional statement is executed: 'alert("Your screen name is " + screenName + " !");'
The next thing concerns what is referred to as concatenation or parsing (putting two or more strings of text together as one).
The previous statement: 'alert("Your screen name is " + screenName + " !");' uses the plus sign to put strings together as one. In AppleScript, we would use the ampersand '&'
<input type="button" onclick="screenNamePrompt()" value="Prompt Screen Name" />
Click on this button to see prompt dialog:
If you have questions or would like to suggest a post, contact me at: hyperscripter@gmail.com or http://twitter.com/hyperscripter


