Click here to Skip to main content
15,886,689 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hai,

Iam designing an email page.I have a textbox where i will enter email addresses.So when there are multiple email's,when i click on backspace instead of removing letter by letter..i have to remove a mail id itself..

For example,

In my textbox iam having mail id's like

abc@gmail.com,xyz@gmail.com,sss@gmail.com

if i click on backspace i have to remove sss@gmail.com at a time instead of removing letter by letter.

Iam trying to do this in asp.net.

Please help me in doing this.
Posted

Refer to this link. It will definitely help you out.

Remove String from Text Box from back[^]

Regards..:)
 
Share this answer
 
You would need to attach an event handler for onkeydown of your text box.

<input type="text" id="txtEmail" önkeydown="myFunction()" />

your javascript function can be like this

C#
function myFunction()
{

if(event.keyCode == 8)
{
var result = "";
var emails = document.getElementById('txtEmail').value.split(",");
for(var i =0; i < emails.length - 1; i++)
{
   result += emails[i] + ",";

}
document.getElementById('txtEmail').value = result;
}

}
 
Share this answer
 
v2
Comments
aswinisolleti 8-Aug-13 5:31am    
thank u very much samresh...it's working..but wat's happening is..if iam having three mail id's and if i want to remove second mail id..it is removing last mail id..
any idea..
[no name] 9-Aug-13 1:37am    
thanku so much samresh..its working fine but ,in that i have some problem i.e i have some mail id like abc@gmail.com,assu@gmail.com,madhu@gmail.com,........., in that where i am clicking that mail only remove..can you please provide any Suggestion.
Thanku.
madhup220@gmail.com
Samresh.ss 27-Aug-13 10:53am    
You can get the index of email id to remove by getting your currrent cursor position
I think this might help
http://stackoverflow.com/questions/2897155/get-cursor-position-within-an-text-input-field

Apologies for replying so late as I was off the grid.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900