Hi there i'm working on this code. id like to enter a form tag so i can have a button thay says "order a drink" then the prompt box appears, rather than it appearing instantly. Im going to have this JS linked to html seperately. What adjustments need to be made to my code? and what will i need in the html file?
any help would be appreceiated.
thanks
my html is blank at the moment, its basically going to have a list of the cocktails available.Code:var mojito ="mojito"; var caipirnha ="caipirnha"; var fruit_caipirinha ="fruit caipirinha"; var iced_tea ="long lsland iced tea"; var seabreeze ="seabreeze"; var lynchburg ="lynchburg"; var esp_martini ="espresso martini"; var cosmpolitan ="cosmopolitan"; var belini ="belini"; var key_west_cooler ="key west cooler"; var drink_wanted = prompt ("please enter the cocktail you would like to make") if (drink_wanted == mojito) { alert ('you have asked for a mojito') } if (drink_wanted == caipirnha) { alert ('you have asked for a caipirnha') } if (drink_wanted == fruit_caipirinha) { alert ('you have asked for a fruit caipirinha') } if (drink_wanted == iced_tea) { alert ('you have asked for a long island iced tea') } if (drink_wanted == seabreeze) { alert ('you have asked for a seabreeze') } if (drink_wanted == lynchburg) { alert ('you have asked for a fruit lynchburg') } if (drink_wanted == esp_martini) { alert ('you have asked for an espresso martini') } if (drink_wanted == cosmpolitan) { alert ('you have asked for a cosmopolitan') } if (drink_wanted == belini) { alert ('you have asked for a fruit belini') } if (drink_wanted == key_west_cooler) { alert ('you have asked for a key west cooler') } else { alert ('sorry, that coktail isn\'t recognised') }
thanks, im kind of new to javascript. so i dont really understand what you mean
yes i get that but whats the code to hold the prompt?
thankyou =]
i acually do have one question.
ive insterted the <input type="button" value="Place Order" />
into my html page.
id rather not have any javascript in there i like it all seperate on another page. how do i make the button bring up the prompt for there?
In the HEAD section of your HTML page, add this:
Then, create a new file called yourscriptfile.js (or whatever) and put this code in:HTML Code:<script src="yourscriptfile.js"></script>
You can then call PlaceOrder() in your input tag.Code:function PlaceOrder() { //All the rest of the code here. }
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks