Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Ajax
|
Ajax the combination of XHTML, CSS, DOM, XML, XSLT, XMLHttpRequest, and JavaScript
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Ajax section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 21st, 2005, 10:44 PM
Authorized User
 
Join Date: Dec 2005
Posts: 21
Thanks: 0
Thanked 1 Time in 1 Post
Default Passing Parameters to a function

I'm learning the basics of AJAX. It's coming along well. Getting the data via xmlHttp wasn't too bad. The problem is updating the page using the DOM.

I want to use an onMouseOver event to pop up a flyover but the information contained in the flyover is dynamic from the xmlHttp request. I need to pass it a parameter. I would normally do a

         onMouseOver="Flyover('My text here')"

However, in the AJAX world I have to use a

         document.getElementById("MyElement").onmouseover = Flyover;

I can't include the parenthesis and so I also can't pass the parameter here. I can't figure out how to pass "My text here" to the function.

 
Old December 22nd, 2005, 06:22 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

Try...
Code:
document.getElementById("MyElement").onmouseover = new Function("Flyover('My text here');");
HTH,

Chris




 
Old December 22nd, 2005, 08:30 AM
Authorized User
 
Join Date: Dec 2005
Posts: 21
Thanks: 0
Thanked 1 Time in 1 Post
Default

That works but now I want send it some dynamically generated text and that doesn't. So the following works fine:
Code:
document.getElementById("MyElement").onmouseover = new Function("Flyover('My text here');");
But if I try this, it doesn't
Code:
var MyString = 'Hello there.';
document.getElementById("MyElement").onmouseover = new Function("Flyover(MyString);");
 
Old December 22nd, 2005, 08:39 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Code:
var MyString = 'Hello there.';
document.getElementById("MyElement").onmouseover = new Function("Flyover(" + MyString+ ");");
This is only going to work if the variable is a string or integer etc, not an object.

--

Joe (Microsoft MVP - XML)
 
Old December 22nd, 2005, 09:12 AM
Authorized User
 
Join Date: Dec 2005
Posts: 21
Thanks: 0
Thanked 1 Time in 1 Post
Default

That didn't work but the following did:
Code:
document.getElementById("MyElement").onmouseover = new Function("Flyover('" + MyString+ "');");
(I added the single quotes)
Thank you very much for the help. I'm a happy camper again.


The Following User Says Thank You to atcs2152 For This Useful Post:
sachingoel0101 (July 5th, 2012)





Similar Threads
Thread Thread Starter Forum Replies Last Post
passing parameters fizzerchris Access VBA 5 August 31st, 2007 12:16 PM
Passing parameters ceema Crystal Reports 0 February 15th, 2006 04:03 AM
passing empty parameters to a js function crmpicco Javascript How-To 0 September 20th, 2005 10:16 AM
Passing parameters to a In([MyParameter]) function Rocket Classic ASP Databases 0 March 17th, 2005 10:21 AM
passing parameters spraveens Javascript How-To 1 October 8th, 2003 03:14 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.