PDA

View Full Version : Invalid Syntax using objDOM.xml.toString()


tcanny
12-10-2002, 04:41 PM
What I'm trying to do is have an email window open on the user's machine and have the contents of an XML file be added as the body of the email. I've gotten the code below to work when not including the myStr variable so I know the mailto: part is working. I also modified the code to have myStr show up in an alert so I know the XML file is loading and stringing. What I need to know is is there something about the content of the string that is causing the Invalid Syntax error and if so what can I do to escape that problem? Or is it something completely different I'm not even thinking about? Thanks in advance for your assistance.


function mailIt() {
var objDOM;
objDOM = new ActiveXObject("Microsoft.XMLDOM");
objDOM.async = false;
objDOM.load("MyXMLFile.xml");
var myStr = objDOM.xml.toString();
var Mail = "mailto:foo@bar.com?subject=MyXMLFile&body=" + myStr;
window.location.href = Mail;
}


The above code is activated with this href:

<a href="#" onclick="javascript:mailIt()">click here</a>

tcanny
12-11-2002, 07:29 PM
I'm wondering if I should have posted this in the Javascript section? Any thoughts on a better spot to post this question in order to get a response? Do you think the question has been mis-posted or is it just not clear what I'm asking? Any feedback will be appreciated. Thanks.

By the way, I decided to end run the issue by putting the xml into a hidden form field using "onload" and then having the user click a button that sends the form via "mailto" however I would like to know if the straight "mailto" scheme I was trying is possible.

Oh, yeah, and what does the little black dot on the envelope icon mean next to my message. Does it just show up for me to identify my messages or is it a sign to all that my message is like a black hole and they should stay away? :]

Alex Vincent
12-12-2002, 11:51 PM
Moving to JavaScript Programming Help Forum. :)

glenngv
12-13-2002, 03:27 AM
Originally posted by tcanny
What I need to know is is there something about the content of the string that is causing the Invalid Syntax error and if so what can I do to escape that problem?


escape() the xml content :D

var Mail = "mailto:foo@bar.com?subject=MyXMLFile&body=" + escape(myStr);

Adam20002
12-13-2002, 12:35 PM
Originally posted by tcanny

var myStr = objDOM.xml.toString();



should the above line not be objDOM.toString(). I haven't really done much work with xml and javascript but the .xml part in the middle just looked stranged.

I might just be talking rubbish on the other hand :D

tcanny
12-13-2002, 02:59 PM
Originally posted by glenngv
escape() the xml content :D

var Mail = "mailto:foo@bar.com?subject=MyXMLFile&body=" + escape(myStr);


I tried the escape and it works! The only problem is I end up with an email filled with escaped text that once it gets to the recipient has to be unescaped. I guess I could have the email processed somehow once it gets to the recipient but that's a little more work than I wanted to do. The file doesn't need to be escaped when I make it populate a hidden field and have a form mail it as enctype="text/plain". Is there a way to set the enctype with a simple mailto: or am I just stuck with using the form? At this point I'm just curious because I'll probably stay with sending it via the form.

Thanks for your assistance.