Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Using select menu to open mailto link

Posted on 2010-09-23
4
Medium Priority
?
755 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 2000 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

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
The viewer will learn how to dynamically set the form action using jQuery.
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…
Suggested Courses

618 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