Aristain Aristain - 6 months ago 23
HTML Question

Copy Only Domain Name from email input

I have an input field for email input and URl input field. On double click i copy mail's value to url like this

<script>
function cp_mail() {
document.getElementById("mail").value = document.getElementById("Url").value;
}
</script>


Now i only want to copy domain name of email (from the "@" to the end) and insert on the begining of Url "www." .Any Ideas ?

Answer

you can write like this

var email="test@domain.com";
var domainName = 'www.' + email.split('@')[1]
Comments