471,895 Members | 2,273 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,895 software developers and data experts.

Js CODE in html tag ......

2,476 2GB
today i experienced an interesting problem with JS.

look at this code carefully .....

<body onload = alert(Msg)>
It works wellll.....

if i write <body onload = confirm(Msg)>
but it does not work...

after seperating the JS CODE with '' or "" ... then it works well

i m working with IE

is it a good practice ... while i writing JS code in HTML TAG.. seperate with '' or "".....??????????
i mean .... with event handling CODE

i want the proper explaination ... thanxxxx in advance
Apr 9 '07 #1
2 1050
16,027 Expert Mod 8TB
The code should be within quotes, but separation is even better where the JavaScript code is separate from the HTML. For example, body onload becomes window.onload=... or even window.addEventListener(...)/window.attachEvent.
Feb 5 '08 #2
5,390 Expert Mod 4TB
always use the quotes! strictly seen - that are not event-handlers but attributes of the node ... and when assigning a value to it the browser handles that attributes to interpret the value as code that should be executed ... so every attribute-value in a html-document's nodes should be quoted ... always :)

kind regards
Feb 5 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

7 posts views Thread by Hansan | last post: by
109 posts views Thread by Andrew Thompson | last post: by
17 posts views Thread by tshad | last post: by
1 post views Thread by Peter Williams | last post: by
26 posts views Thread by webrod | last post: by
25 posts views Thread by Jon Slaughter | last post: by
reply views Thread by zermasroor | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.