Click here to Skip to main content
15,917,177 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
i have a text box and label

i want to remove a particular text from given text box for ex

when i enter text aabbcc
i want to remove aa and show in alert as bbcc


<asp:TextBox ID="txtname" runat="server">
<asp:Label ID="Label1" runat="server" Text="">


<asp:Button ID="btnClick" runat="server" Text="Click" OnClientClick="Click();" />




function Click() {
alert("1");
var str = document.getElementById('txtname').value;
alert(str);
document.getElementById('Label1').value = str;
alert(document.getElementById('Label1').value);

}
Posted
Updated 19-Jun-15 23:11pm
v2

On change of the TextBox, fire an event and inside that take the value of TextBox. Then call a stored procedure or write a query, which will split the word into letters and keep matching the words present in the required column.
 
Share this answer
 
Comments
Member 11382784 20-Jun-15 5:19am    
when click button i want to remove a letter (anything i.e a or b or c) and show remaining in alert box

for example(deleting 'a' from text box entry and showing remaining in alert using javascript )
i have entered madhu in text box
i want to show in alert as mdhu
mystring = mystring.replace(/\/a/g, '');
Thanks7872 20-Jun-15 5:28am    
Stored procedure? Query? Ummm....why?
Actually the question is edited. It was different before. The past question was to get the correct word from database.
Member 11382784 20-Jun-15 6:30am    
yes sir ,
sorry for that

and how to bind the value to label . i have tried but it is not working

var str = document.getElementById('txtname').value;

str = str.replace(/[^c-z\.]+/g, '');
document.getElementById('Label1').value = str;
These are what you need to write the code:
1. Use substring()[^] method extracts the characters that you want from a string
2. Use ASP.NET 4.0 Client ID Feature[^] to identify the control in asp.net
3. Use the onblur Event[^] to fire the function.
 
Share this answer
 
Comments
Member 11382784 20-Jun-15 6:02am    
function Click() {
alert("1");
var str = document.getElementById('txtname').value;

str = str.replace(/[^0-9\.]+/g, '');
alert(str);

by using this js am removing letters and it printing only numbers
actually i want to remove particlar letters a or b or c
Peter Leow 20-Jun-15 6:30am    
You have changed the question. If you know the letter to remove, say a, or b, then str.replace(/[ab]+/g, ''); will do.
Find out more about regex yourself http://www.codeproject.com/Articles/9099/The-Minute-Regex-Tutorial.

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