Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript in IE7

Status
Not open for further replies.

aarellano

MIS
Oct 22, 2007
168
US
Hello,
I have a script that used to work with IE6 some of the workstations got upgrated with IE7 and now my javascript does not work. for the life of me I cannot see what is wrong with it.
Code:
<script>
function initialize()
{
 document.forms['form'].elements['email'].value = temp ;
}
</script>




<script type=text/javascript>

function openoutlook()
{
  var S=document.form.customer.value;
  var B=document.form.comments2.value;
  var M=document.form.email.value;
  var A= <% = request.querystring("id") %>
  var url = '[URL unfurl="true"]http://myweb/view1.asp?id='[/URL] + escape(A);

  
 self.location="mailto:abc@mysite.com?subject=An Update Has Been Made To abc Project # "+A+" By "+M+"&body="+M+" Updated Project # "+A+" .  Here is the link to the project  "+url;
}
</script>

any help would be very much appreciated

thanks

aarellano
 
sorry I forgot to post the submit
Code:
<input type="submit" name="Submit"  onclick="openoutlook()" value="submit">
 
It's particularly difficult to try to debug an error when you don't state what the error is.

However, I can make a few generalized comments about your code.

Let's start by breaking the page down to it's core elements. You want a javascript function to kick off to send out an email via outlook. Sometimes IE7 will block events that are automatically fired when a page loads (via the onload handler), so we can test for both instances:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
<title>test</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<script type="text/javascript">

window.onload = blah;

function blah() {
   self.location = "mailto:a@b.com?subject=test&body=test";
}

</script>
<style type="text/css"></style>
</head>
<body>

<input type="button" value="click me" onclick="blah()" />

</body>
</html>
In IE7 this worked fine for me. Outlook opens a new mail message when I first load the page, and also when I click the button. So, we know that the issue is that your code is not getting blocked by an onload handler.

Looking at your code I can point out a few things:
Code:
[purple]<script>[/purple]
function initialize()
{
 [green]document.forms['form'].elements['email'].value[/green] = temp ;
}
</script>




<script type=[COLOR=pink]text/javascript[/color]>

function openoutlook()
{
  var S=[red]document.form.customer.value;[/red]
  var B=[red]document.form.comments2.value;[/red]
  var M=[red]document.form.email.value;[/red]
  var A= [blue]<% = request.querystring("id") %>[/blue]
  var url = '[URL unfurl="true"]http://myweb/view1.asp?id='[/URL] + escape(A);

  
 self.location="mailto:abc@mysite.com?subject=An Update Has Been Made To abc Project # "+A+" By "+M+"&body="+M+" Updated Project # "+A+" .  Here is the link to the project  "+url;
}
</script>

1) In the purple <script> tag you have not specified the type attribute, however you do it in the second <script> tag.
2) When specifying the pink value for the type attribute in the 2nd script tag, you did not encapsulate the value in quotes.
3) You correctly use the forms and elements collections (noted in green) in the first <script> tag, but then you abandon that practice in the second <script> tag (noted in red)
4) You pull the id value directly from the querystring and throw it to the page (noted in blue) with no regard for what type of data may exist there. This would not be that big of a problem except for the fact that you are not encapsulating that value in quotes - forcing it to become a string. If there is a numeric value in the querystring the javascript compiler will have no problem parsing the statement. However, if any non-numeric characters exist then it will crash. You may not structure your page to ever have a non-numeric value in the querystring, but since you're pulling the data from the querystring it means that any user can manipulate that value directly from their browser address bar.
5) And another thing you've added since I started typing this reply is that the the function is triggered from a submit button. Submit buttons are used to submit form data to a specified page. If you're just wanting to trigger this function then you shouldn't be using an input of type "submit" - you should use an input of type "button".
6) yet another thing that you've added since I started typing this reply - you named your submit button "submit". This is extremely bad practice since there is a method already called submit. Using your non-standard code from above where you did not use the forms and element collections, what if you constructed a line of code like this:
Code:
var a = document.form.submit
Are you referencing the submit button, or the submit method? The javascript compiler won't know and it's sure not going to make a guess at what it thinks you mean.


You show a lot of good practice in some of your code above, but then in other spots.... not so much. You should try to be more consistent when writing your code. You will run into many less errors that way.

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson

[small]<P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B>[/small]
 
kaht,

Thank you for all the advice. and you are abolutly right I did forget to specify the problem.
So here it goes. I have an asp edit page in this page users can make modifications to the data. When they click the submit button it opens outlook and inserts the name of the email address, also on the CC it add the name of the person that made the change. then on the subject it indicates that a change was made to record number xxx . On the body of the email I insert a link to the specified record so that the user can click on the link and they go to the view of the record. This script has been working well. But when IE 6 was updated to IE7 that is when things started to get a bit odd.
The script still opens outlook and inserts the e-mail address, and the subject.
the CC name and the link in the body of the e-mail do not show up.
 
The script still opens outlook and inserts the e-mail address, and the subject.
the CC name and the link in the body of the e-mail do not show up.

In your code above, nowhere are you defining a cc for the email:
Code:
 self.location="mailto:abc@mysite.com?subject=An Update Has Been Made To abc Project # "+A+" By "+M+"&body="+M+" Updated Project # "+A+" .  Here is the link to the project  "+url;

Are you posting the actual code, or are you chopping up bits and pieces to show?

With the information given, I can only give you 2 bits of advice.

First, do all the things I mentioned in my first post to clean your page up.

And second, break down the mailto url to it's basics. Don't construct an elaborate string from all the input boxes on the page. Make it a static string like the one I showed you in my first post. Do it as a proof of concept so that you can see for yourself that it will work in IE7. Then, start slowly adding elements back into the string from the form until it breaks. Then you'll know what's causing the problem.

Also, it might be helpful to construct the mailto url in a separate variable, alert the variable, and then set the self.location to the variable - that way you can see exactly what is being constructed.

Code:
var blah = "mailto:abc@mysite.com?subject=An Update Has Been Made To abc Project # "+A+" By "+M+"&body="+M+" Updated Project # "+A+" .  Here is the link to the project  "+url;
alert(blah)
self.location = blah;

Ok... so that was 3 suggestions.

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson

[small]<P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B>[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top