Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple code does not work

Status
Not open for further replies.

modeler1

Technical User
Jun 17, 2001
2
US
Anyone know why this does not work?????????????



<HTML>

<TITLE>
Example of passing parameters
// If it works, it should display &quot;I had Creme Brulet for lunch. It was delicious&quot;.
</TITLE>

<BODY>

<CENTER>

<FORM>
<BR>
<BR>
<INPUT TYPE=BUTTON Value=&quot;Click here if you want to find out what I had for lunch?&quot; onClick=&quot;MyLunch(Creme Brulet, delicious)&quot;>
</FORM>

</CENTER>

</BODY>

<SCRIPT LANGUAGE=JavaScript>
function MyLunch(food, rating)
{
window.alert(&quot;I had&quot; + food + &quot;for lunch. It was&quot; + rating);
}
</SCRIPT>

</HTML>
 
It was almost correct ;-)

onClick=&quot;MyLunch('Creme Brulet', 'delicious')&quot;

...and you'll probably want to change the following line as well (just the spaces, you'd have noticed this as well):

window.alert(&quot;I had &quot; + food + &quot; for lunch. It was &quot; + rating);

Hope this helps...
allow thyself to be the spark that lights the fire
haslo@haslo.ch - www.haslo.ch​
 
& notice that u shuld place script into head of the document (in your example – it is not there…)
 
You don't need to qualify &quot;alert&quot; with &quot;window.&quot;

You should close the <body> with </body>.


I think between us we've covered just about every line...

Don't get disheartened - you're still on the easy stuff!

Stephen
 
hi vituz,
scripts can be placed anywhere inside a html page and not necessarily at the <head> section even though it is advisable to place it there........

and modeler as haslo told enclose the arguments with single quotes...bcoz u want to pass literals to the function and what u have passed in ur code is a variable.....okay?? Take care

Regards,
R.Subramanian
 
hie
>>rsubras
about scripts placement - yeah, eggzactly, i wrote should but not have to - it was just kinda advise
:)
my arguments:
1. when u put your functions at the <head> it is 'a priori'
known that all variables wuld be defined & all necessary actions wuld be done before the user wuld start any activity on the page
2. it is better & more pleasing (at least for me) 2 c thus builded documents than 2 seek for scripts & functions in the entire body section, & i think this structure wuld add some culture, punctuality & style (may be your own one) 2 your pages & u'll be able 2 edit your pages spendin much less time for it. (sorry for my english)

regards, vic
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top