Solved

Using select menu to open mailto link

Posted on 2010-09-23
4
744 Views
Last Modified: 2012-05-10
I've got a select menu with a list of names and emails, when you click one I want the email client to open up as it would on a normal mailto link. The problem is it keeps opening up a new window and the email client!

I've tried the following code with preventDefault and return false but to no avail!

Thanks in advance.

Chris
$(document).ready(function(){
	$("#contacts").change(function() {
		if (this.value != "") {
			location.href='mailto:'+$(this).val(); 
		}
	});
});

Open in new window

0
Comment
Question by:djfenom
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 

Author Comment

by:djfenom
ID: 33742128
It's only in IE by the way!
0
 
LVL 14

Expert Comment

by:Dushyant Sharma
ID: 33742330
Your codes seems to be working fine for me.

i have used.

<script src="jquery-1.3.2.min.js"></script>
        <script type="text/javascript">
            $(document).ready(function(){
                $("#contacts").change(function() {
                    if (this.value != "") {
                        location.href='mailto:'+$(this).val();
                    }
                });
            });

        </script>
        <select id="contacts">
            <option value="abcd@xyz.com">abcd</option>
            <option value="abcd1@xyz.com">abcd1</option>
            <option value="abcd2@xyz.com">abcd2</option>

        </select>

this is working as expected and i do not see any additional window. I have checked this in ie6 7 and ff
0
 

Author Comment

by:djfenom
ID: 33742726
I've got this:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
      $("#contacts").change(function() {
            if (this.value != "") {
                  location.href='mailto:'+$(this).val();
            }
      });
});
</script>
<select name="contacts" id="contacts">
            <option value="" selected="selected">Contact Us:-</option>
            <option value="blah@blah.co.uk">Blah</option>
            <option value="blah@blah.co.uk">Blah</option>
            <option value="blah@blah.co.uk">Blah</option>
            <option value="blah@blah.co.uk">Blah</option>
            <option value="blah@blah.co.uk">Blah</option>
          </select>
0
 
LVL 14

Accepted Solution

by:
Dushyant Sharma earned 500 total points
ID: 33743193
This too  is working fine for me, as it should be. on changing the select option it opens up the email client.
No other window opening up.
0

Featured Post

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question