Jump to content

prompt to to appear after onclick

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
19 replies to this topic

#1
freddyw2

freddyw2

    Newbie

  • Members
  • PipPip
  • 12 posts
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


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')

}




my html is blank at the moment, its basically going to have a list of the cocktails available.

#2
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
Make an order button, then assign some code to its onclick event.
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#3
freddyw2

freddyw2

    Newbie

  • Members
  • PipPip
  • 12 posts
thanks, im kind of new to javascript. so i dont really understand what you mean

#4
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
In the HTML, you create a button. Then, you set its onclick attribute to some JS code that you have typed. OK?
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#5
freddyw2

freddyw2

    Newbie

  • Members
  • PipPip
  • 12 posts
yes i get that but whats the code to hold the prompt?

#6
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
<input type="button" value="Place Order" onclick="JAVASCRIPT GOES HERE" />

Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#7
freddyw2

freddyw2

    Newbie

  • Members
  • PipPip
  • 12 posts
thankyou =]

#8
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
You are welcome. If you have any more queries then just ask.
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#9
freddyw2

freddyw2

    Newbie

  • Members
  • PipPip
  • 12 posts
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?

#10
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
In the HEAD section of your HTML page, add this:

<script src="yourscriptfile.js"></script>

Then, create a new file called yourscriptfile.js (or whatever) and put this code in:


function PlaceOrder()
{
 //All the rest of the code here.
}


You can then call PlaceOrder() in your input tag.
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#11
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
You have to have a trigger on the input tag, though you can have it call a function that is loaded from an external .js file.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#12
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
That's what I put in my post, Winged, no?
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums