©ilj@flowsim.se JavaScript code samples 27 JavaScript prompt() >>> this example in Swedish |
![]() click here to display a JavaScript prompt ! code & explanations further down ![]() ![]() ![]() |
Clicking on <A HREF = "#" ![]() PROMPT</A> calls the function iljprompt(). Put the function within SCRIPT tags in the HEAD portion of the document, see MINIMANUAL 1 basics. function iljprompt() { backpict = new Array() backpict[1]='picture file 1' backpict[2]='picture file 2' iljpromptback=prompt('Choose background picture 1 or 21','12')3 if(iljpromptback)4 { iljpromptnamn=prompt('Your name, please!1','anonymous2')5 if(iljpromptnamn)6 { iljhtmlwin=window.open('','','width=250,height=250')7 iljhtmlwin.document.open() iljhtmlwin.document.write("<BODY BACKGROUND=" +backpict[iljpromptback]+"><FORM>Hi there"+iljpromptnamn +"<INPUT TYPE = 'button'VALUE= 'close'onClick='self.close()'></FORM>")8 iljhtmlwin.document.close() } } } 1 this is where you write the text that is to be written directly on the prompt window 2 and this is where you write text you want to display in the textbox - if you want the textbox to be empty, keep the quotation marks but donīt write anything between them 3 the first prompt which is shown directly as you click the "link" - the text from iljpromptback= to the parenthesis in front of footnote 3 should be put on one line - iljpromptback here takes the value of the number the user has written in the textbox 4 if the user clicked OK and something is written in the text box in the first prompt the second one will be shown 5 the second prompt - one line from iljpromptnamn= to the parenthesis in front of footnote 5 6 if the user chose OK in the second prompt the new window will be opened 7 this line opens the new window and determines its appearance etc - more about this under 26 opening new browser windows 8 on this line (from iljhtmlwin.document.write) you decide what is to be written to the new page. Between the third and fourth curly brace from the end there should (the way Iīve written the code) be only four lines all of them starting with iljhtmlwin. Suitable places to start a new line are, otherwise, immediately before or after the plus signs (which are connecting the text strings and the variables ). Everything that is to be quoted on the new page is to be put within parentheses. OTHER JAVASCRiPT EXAMPLES ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Page by ![]() ilj@flowsim.se ![]() Last modified: January 12, 1998 This page is part of a frames system at: http://www.flowsim.se JAVASCRiPT |