Code works with HTML 4.0 Transitional DOCTYPE, but not with XHTML 1.0 Transitional

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tader
    New Member
    • Sep 2007
    • 43

    Code works with HTML 4.0 Transitional DOCTYPE, but not with XHTML 1.0 Transitional

    so i got script like that

    [HTML]
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
    <head>
    <title>Drag and Drop</title>
    <style>
    #slater {
    display:block;
    width:13px;
    height:22px;
    background:url( slater.gif);
    cursor:pointer;
    position:relati ve;
    border:0px;
    }
    #main_box {
    position:relati ve;
    width:113px;
    height:22px;
    background:url( background_slat e.jpg) no-repeat;
    border:0px;
    }
    </style>
    <script>

    if (navigator.appN ame == "Microsoft Internet Explorer") { var Browser = "IE"; } else { var Browser = "FF"; }
    var MoveIT = "";

    function startDrag() {
    OffsetX = MouseX - (document.getEl ementById('slat er').style.left ).replace("px", "");
    MoveIT = "yes";
    }

    function mouseMoveFF(eve nt) {
    MouseX = event.clientX;
    if (MoveIT == "yes") {
    document.getEle mentById('slate r').style.left = MouseX - OffsetX;

    if(document.get ElementById('sl ater').style.le ft.replace("px" ,"") <= 0) {
    document.getEle mentById('slate r').style.left = 0+"px";
    } else if ((document.getE lementById('sla ter').style.lef t.replace("px", "")) >= 100) {
    document.getEle mentById('slate r').style.left = 100+"px";
    }

    var speed = document.getEle mentById('slate r').style.left. replace("px","" ) / 10;
    var fix_pt = (document.getEl ementById('slat er').style.left != "0pt") ? speed : '0';
    document.getEle mentById('speed ').innerHTML = fix_pt;
    }
    }

    function mouseMoveIE() {
    MouseX = event.clientX;
    if (MoveIT == "yes") {
    document.getEle mentById('slate r').style.left = MouseX - OffsetX;

    if(document.get ElementById('sl ater').style.le ft.replace("px" ,"") <= 0) {
    document.getEle mentById('slate r').style.left = 0+"px";
    } else if ((document.getE lementById('sla ter').style.lef t.replace("px", "")) >= 100) {
    document.getEle mentById('slate r').style.left = 100+"px";
    }

    var speed = document.getEle mentById('slate r').style.left. replace("px","" ) / 10;
    document.getEle mentById('speed ').innerHTML = speed;
    }
    }

    if (Browser == "IE") { document.onmous emove = mouseMoveIE; } else { document.onmous emove = mouseMoveFF; }
    document.onmous eup = function () { MoveIT = ""; }

    </script>
    </head>
    <body>

    <div id="main_box">
    <div id="slater" onMouseDown="st artDrag()"></div>
    </div>
    <div id="speed" style="font-family:Arial, Helvetica, sans-serif; font-size:10px; color:#666666;" >0</div>
    </body>
    </html>
    [/HTML]
    so it works file but this is my problem it's made on <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> HTML 4.0 Transitional i need it to be <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d"> but this i my problem when i change HTML 4.0 Transitional to XHTML 1.0 Transitional it stops working so can some one tell me how to make my script work with XHTML 1.0 Transitional (on ie XHTML 1.0 Transitional works but not on FF)
  • mrhoo
    Contributor
    • Jun 2006
    • 428

    #2
    Take the script out of the html and link to it with
    <script type="text/javascript" src=></script> in the head, and include a title element in the head.
    put the event assignment in an onload call in the remote script.

    Comment

    • tader
      New Member
      • Sep 2007
      • 43

      #3
      i did like this and it still not working
      [HTML]
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
      <html xmlns="http://www.w3.org/1999/xhtml">
      <head>

      <meta http-equiv="Content-Type" content="text/html; charset=windows-1257" />
      <title>Drag</title>
      <script type="text/javascript" language="javas cript" src="script.js" ></script>
      <link type="text/css" rel="stylesheet " href="css.css" />

      </head>
      <body>
      <div id="main_box">
      <div id="slater" onMouseDown="st artDrag()"></div>
      </div>
      <div id="speed">0</div>
      </body>
      </html>
      [/HTML]

      have any ideas hat to do now??
      but on ie it works

      Comment

      • tader
        New Member
        • Sep 2007
        • 43

        #4
        onload is not working or ma bey im not using it right can you tell me how to use it???

        Comment

        • acoder
          Recognized Expert MVP
          • Nov 2006
          • 16032

          #5
          Can you show what code you've tried?

          PS. changed the thread title to better describe the problem.

          Comment

          • tader
            New Member
            • Sep 2007
            • 43

            #6
            HTML Code:
            [HTML]
            <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
            <html xmlns="http://www.w3.org/1999/xhtml">
            <head>

            <meta http-equiv="Content-Type" content="text/html; charset=windows-1257" />
            <title>Drag</title>
            <script type="text/javascript" language="javas cript" src="script.js" ></script>
            <link type="text/css" rel="stylesheet " href="css.css" />

            </head>
            <body>
            <div id="main_box">
            <div id="slater" onMouseDown="st artDrag()"></div>
            </div>
            <div id="speed">0</div>
            </body>
            </html>
            [/HTML]

            Javascript code:
            Code:
            if (navigator.appName == "Microsoft Internet Explorer") { var Browser = "IE"; } else { var Browser = "FF"; }
            var MoveIT = "";
            	
            function startDrag() {
            	OffsetX = MouseX - (document.getElementById('slater').style.left).replace("px","");
            	MoveIT = "yes";
            }
            		
            function mouseMoveFF(event) {
            	MouseX = event.clientX;
            	if (MoveIT == "yes") {
            		document.getElementById('slater').style.left = MouseX - OffsetX;
            
            		if(document.getElementById('slater').style.left.replace("px","") <= 0) {
            			document.getElementById('slater').style.left = 0+"px";
            		} else if ((document.getElementById('slater').style.left.replace("px","")) >= 100) {
            			document.getElementById('slater').style.left = 100+"px";
            		}
            
            		var speed = document.getElementById('slater').style.left.replace("px","") / 10;
            		var fix_pt = (document.getElementById('slater').style.left != "0pt") ? speed : '0';
            		document.getElementById('speed').innerHTML = fix_pt;
            	}
            }
            	
            function mouseMoveIE() {
            	MouseX = event.clientX;
                if (MoveIT == "yes") {
            		document.getElementById('slater').style.left = MouseX - OffsetX;
            			
            		if(document.getElementById('slater').style.left.replace("px","") <= 0) {
            			document.getElementById('slater').style.left = 0+"px";
            		} else if ((document.getElementById('slater').style.left.replace("px","")) >= 100) {
            			document.getElementById('slater').style.left = 100+"px";
            		}
            			
            		var speed = document.getElementById('slater').style.left.replace("px","") / 10;
            		document.getElementById('speed').innerHTML = speed;
                }
            }
            	
            if (Browser == "IE") {  document.onmousemove = mouseMoveIE; } else { document.onmousemove = mouseMoveFF; }
            document.onmouseup = function () { MoveIT = ""; }
            So like i sad before on ie it works but not on ff. I just cant find the bug

            Comment

            • acoder
              Recognized Expert MVP
              • Nov 2006
              • 16032

              #7
              Move the onmousedown in the slater div into an onload.

              Comment

              • tader
                New Member
                • Sep 2007
                • 43

                #8
                sorry did not understand can you show me an example?

                Comment

                • acoder
                  Recognized Expert MVP
                  • Nov 2006
                  • 16032

                  #9
                  Originally posted by tader
                  sorry did not understand can you show me an example?
                  For example:
                  [CODE=javascript]window.onload=f unction() {
                  document.getEle mentById("slate r").onmousedown =startDrag;
                  }[/CODE] You could use addEventListene r/attachEvent instead.

                  Comment

                  • tader
                    New Member
                    • Sep 2007
                    • 43

                    #10
                    [CODE=javascript]
                    window.onload = function() {
                    if (Browser == "IE") {
                    document.getEle mentById("slate r").onmousem ove = mouseMoveIE;
                    } else {
                    document.getEle mentById("slate r").onmousem ove = mouseMoveFF;
                    }
                    }[/CODE]
                    i did it like this bus it still is not working

                    Comment

                    • acoder
                      Recognized Expert MVP
                      • Nov 2006
                      • 16032

                      #11
                      In your HTML code you have:
                      [HTML]<div id="slater" onMouseDown="st artDrag()"></div>[/HTML] Have you removed the onMouseDown?

                      Comment

                      • tader
                        New Member
                        • Sep 2007
                        • 43

                        #12
                        i dind remove this onmousedown=sta rtdarg();
                        heres my javascript
                        still it's nowworking on ff but working on ie
                        [CODE=javascript]
                        if (navigator.appN ame == "Microsoft Internet Explorer") { var Browser = "IE"; } else { var Browser = "FF"; }
                        var MoveIT = "";

                        function startDrag() {
                        OffsetX = MouseX - (document.getEl ementById('slat er').style.left ).replace("px", "");
                        MoveIT = "yes";
                        }

                        function mouseMoveFF(eve nt) {
                        MouseX = event.clientX;
                        if (MoveIT == "yes") {
                        document.getEle mentById('slate r').style.left = MouseX - OffsetX;

                        if(document.get ElementById('sl ater').style.le ft.replace("px" ,"") <= 0) {
                        document.getEle mentById('slate r').style.left = 0+"px";
                        } else if ((document.getE lementById('sla ter').style.lef t.replace("px", "")) >= 100) {
                        document.getEle mentById('slate r').style.left = 100+"px";
                        }

                        var speed = document.getEle mentById('slate r').style.left. replace("px","" ) / 10;
                        var fix_pt = (document.getEl ementById('slat er').style.left != "0pt") ? speed : '0';
                        document.getEle mentById('speed ').innerHTML = fix_pt;
                        }
                        }

                        function mouseMoveIE() {
                        MouseX = event.clientX;
                        if (MoveIT == "yes") {
                        document.getEle mentById('slate r').style.left = MouseX - OffsetX;

                        if(document.get ElementById('sl ater').style.le ft.replace("px" ,"") <= 0) {
                        document.getEle mentById('slate r').style.left = 0+"px";
                        } else if ((document.getE lementById('sla ter').style.lef t.replace("px", "")) >= 100) {
                        document.getEle mentById('slate r').style.left = 100+"px";
                        }

                        var speed = document.getEle mentById('slate r').style.left. replace("px","" ) / 10;
                        document.getEle mentById('speed ').innerHTML = speed;
                        }
                        }

                        window.onload = function() {
                        if (Browser == "IE") {
                        document.getEle mentById("slate r").onmousem ove = mouseMoveIE;
                        } else {
                        document.getEle mentById("slate r").onmousem ove = mouseMoveFF;
                        }
                        }


                        document.onmous eup = function () { MoveIT = ""; }
                        [/CODE]

                        Comment

                        • acoder
                          Recognized Expert MVP
                          • Nov 2006
                          • 16032

                          #13
                          Originally posted by tader
                          i dind remove this onmousedown=sta rtdarg();
                          heres my javascript
                          still it's nowworking on ff but working on ie
                          You'll need to add the onmousedown to the onload too.

                          Comment

                          • tader
                            New Member
                            • Sep 2007
                            • 43

                            #14
                            if i do it like this
                            [CODE=javascript]
                            window.onload = function() {
                            document.getEle mentById("slate r").onmoused own = startdarg;
                            if (Browser == "IE") {
                            document.getEle mentById("slate r").onmousem ove = mouseMoveIE;
                            } else {
                            document.getEle mentById("slate r").onmousem ove = mouseMoveFF;
                            }
                            }
                            [/CODE]
                            it will not work nor even on ie

                            Comment

                            • acoder
                              Recognized Expert MVP
                              • Nov 2006
                              • 16032

                              #15
                              The onmousemove should probably be on the document:
                              Code:
                              document.onmousemove = ...
                              as you originally had it.

                              It's startDrag (JavaScript is case-sensitive).

                              Comment

                              Working...