Solved

Using select menu to open mailto link

Posted on 2010-09-23
4
732 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
  • 2
  • 2
4 Comments
 

Author Comment

by:djfenom
Comment Utility
It's only in IE by the way!
0
 
LVL 14

Expert Comment

by:ddsh79
Comment Utility
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
Comment Utility
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:
ddsh79 earned 500 total points
Comment Utility
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
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)
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now