Jump to content

Using the ' in javascript


WhiskyLima
 Share

Recommended Posts

Hi guys, im extreamly new to javascripting and have been doing a little reading. I'm basically making a form which you enter information into and it spits a web page out based on the info. How do I get this line to work?...

myWindow.document.write('<a href="home.html" class="title" onMouseOver="image.src='images/content/bigon.jpg'" onMouseOut="image.src='images/content/big.jpg'"><img src="images/content/big.jpg" align="right" class="point" name="image" alt="">');

I'm probably doing this totally wrong, but Im trying to get it to write a basic mouseover event into the new page im creating. I can see that it's issues lie with the use of the ' in the actual mouseover code.As always, any help would be greatly appreciated.

Link to comment
Share on other sites

In many programming languages, when you need a quotation mark to be printed as a character, you must escape it. Example:Won't work: s = '<a onclick="alert('me')"></a>'Does work: s = '<a onclick="alert(\'me\')"></a>'The slash in this context is called the escape character. It causes control-type characters to be understood as actual characters.On another topic, I'm a little concerned about "image.src." Has "image" been defined somewhere else, or are you just hoping it will be understood as the <img> contained by the <a></a> element? (It won't be.)

Link to comment
Share on other sites

Ahh, that makes sence, I'm not sure about the defining name, I just used "image" as the name for the actual image. It works in the HTML code, not sure if it will work here, but i'll let you know. Thanks very much for the input! :)EDIT: Yep, just tested it, works a treat! Thanks again

Edited by WhiskyLima
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...