469,294 Members | 1,632 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,294 developers. It's quick & easy.

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 1031
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 zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.