Link to home
Start Free TrialLog in
Avatar of djfenom
djfenom

asked on

Using select menu to open mailto link

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

Avatar of djfenom
djfenom

ASKER

It's only in IE by the way!
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
Avatar of djfenom

ASKER

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>
ASKER CERTIFIED SOLUTION
Avatar of Dushyant Sharma
Dushyant Sharma
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial