Js CODE in html tag ......

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dmjpro
    Top Contributor
    • Jan 2007
    • 2476

    Js CODE in html tag ......

    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
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    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.addEvent Listener(...)/window.attachEv ent.

    Comment

    • gits
      Recognized Expert Moderator Expert
      • May 2007
      • 5390

      #3
      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

      Comment

      Working...