473,806 Members | 2,697 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Moving text with javascript

I have the following code to move some text with javascript that works
both on ie and ff. I can't make it XHTML compatble. If i remove the
doctype info it will work. I'm sorry to bother with such simple
question but is there someone to see where am i wrong?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>ti tle</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /
>
<script type="text/javascript">
function TextMove(val) {
try {
var divObj = document.getEle mentById("mouse Coord");
divObj.innerHTM L = "Moving";
divObj.style.le ft=parseInt(val );
}
catch (ex) { alert (ex); }
}
</script>
</head>
<body onload="TextMov e(0);">
<div>
<div id="mouseCoord " onmouseover="Te xtMove(10);"
onmouseout="Tex tMove(0);" style="position :relative;">&nb sp;</div>
</div>
</body>
</html>

May 3 '07 #1
1 11071
On May 3, 6:42 pm, "mmal...@gmail. com" <mmal...@gmail. comwrote:
I have the following code to move some text with javascript that works
both on ie and ff. I can't make it XHTML compatble. If i remove the
doctype info it will work. I'm sorry to bother with such simple
question but is there someone to see where am i wrong?
Use HTML.
>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>ti tle</title>
Use 2 spaces for indenting posted code, it doesn't wrap quite so
readily.

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /

<script type="text/javascript">
function TextMove(val) {
try {
var divObj = document.getEle mentById("mouse Coord");
try...catch should be reserved as an absolute last resort - feature
detection is much preferred:

var divObj;
if (!document.getE lementById ||
!(divObj = document.getEle mentById("mouse Coord"))) {
return;
}

divObj.innerHTM L = "Moving";

If you really are using XHTML (i.e. you are serving it as application/
xml), then you probably shouldn't be using innerHTML. There's no
standard for innerHTML, so whether it *should* work with XHTML or not
is moot - but it comes from a company whose browser doesn't understand
XML.

I would try straight DOM methods:

while (divObj.firstCh ild) {
divObj.removeCh ild(divObj.firs tChild);
}
divObj.appendCh ild(document.cr eateTextNode('M oving'));
Though the innerHTML alternative worked fine for me in Safari and
Firefox.

divObj.style.le ft=parseInt(val );
The style object's left property expects to get a string value, and
any value other than zero must have a unit (I'll assume you want px):

divObj.style.le ft = val + 'px';
Here's the function in one piece:

function TextMove(val) {
var divObj;

// Feature test
if ( document.getEle mentById &&
(divObj = document.getEle mentById("mouse Coord"))) {

// Remove contents
while (divObj.firstCh ild) {
divObj.removeCh ild(divObj.firs tChild);
}

// Add required text
divObj.appendCh ild(document.cr eateTextNode('M oving'));

// Jiggle the element
divObj.style.le ft = val + 'px';
}
}
--
Rob

May 3 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1758
by: Andi B | last post by:
Hi everyone. I have a quick question - if I have a form which refers to a javascript when its submitted using: <form name = "fred" onsubmit = "test()"> and this function creates a popup window to display information in, I find that after the window has appeared, the focus moves back to the form and the text box used to gather user input clears. The clearing text box isnt a
4
1804
by: Jake j | last post by:
To those of you who sent me working examples of js include routines, much thanks. I see from them examples that what I'm trying to get to requires a higher level of js knowledge than I've got. Here's what I'm really trying to do: I've been using a sliding banner javascript routine in several html files and it works fine. Rather than duplicate the code in each file, however, it would obviously be preferable to including the routine in...
10
3118
by: Mark McLellan | last post by:
Dear all Following the oft-repeated advice here and ciwas I have made my site nearly 4.01 strict (working on it). There are some items on which I would appreciate your advice: 1. Hidden fields http://www.zoo.co.uk/~mmenterprises/contact.htm I am using FormMail from Matt's Script Archive. The W3C validator objected to the hidden fields unless I put, say, P round them. That gave
1
2412
by: OwlHoot | last post by:
I am using Thomas Fuchs's amazing drag-and-drop JavaScript library available at: http://wiki.script.aculo.us/scriptaculous/show/DragAndDrop to allow the user to select a subset of items listed in one box by dragging them to another and sort them in the latter, and it works a treat. However, I'd now like to add a couple of buttons, "<<" and ">>" between
1
3127
by: JohnIdol | last post by:
Hi all, a quick one here. I am moving elements on the page clientside and I am going through strange issues. This one works: <html> <head> <title>Javascript Text</title>
2
3329
by: jonny | last post by:
I am using Visual Web Developer with ASP and VB.NET to build website. I would like to have Text moving across my screen that says "Example text moving across screen for viewers to read.". I am new to web and VB.NET programming so please help me with step by step. (Just when I got used to VB 6.0 now I have to starting learning VB.NET)
1
5083
by: madflytom | last post by:
Hello, I'm trying to move the options of one select list to another select list. The "source" select list is divided into optgroups, and the "target" select list is not. I want to somehow keep track of the moved option's optgroup, so that if I remove it from the "target" select list, it moves back into it's respective optgroup in the "source" select list. I have things moving back and forth, but I'm not sure how to handle the optgroup...
10
6785
by: cjparis | last post by:
Hello everyone. If anyone can give me a hand I would be gratefull Am doing a site which requires a moving element and have used DHTML to do it. Have a simple Browser detect script to sort IE from Netscape. IE is ok but the Netscape browser including Firefox and Safari are not working now. Not sure why. The idea is that when you mouseover the arrows the gallery div moves to left and right. I have changed the script and now the image...
3
1722
by: mrrolf | last post by:
Hi all! I have some pictures on a page that I'm moving around with javascript. I'm just setting the style.top member. I don't want the image to overflow the parent container if I move it to a 'bad' position. I'm setting the overflow attribute in the style, but I'm still seeing the image go outside of the boundaries. Any idea's what I'm missing? var Obj = document.getElementById( "imageId1" ) if( Obj ) { var currPosValue = 0;
0
9719
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9598
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10371
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9192
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5546
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5683
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4330
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3852
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3010
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.