Click here to Skip to main content
15,913,854 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have multiple block o a single webpage ad each block have multiple textbox.
i want to create a single function which is clear all textbox of single block not all block
Posted

1 solution

Use jQuery, try this:
XML
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("button").click(function(){
    $(this).siblings("input:text").val("");
  });
});
</script>
</head>
<body>
<div style="border: 2px solid red; margin: 10px">
<input type="text" value="apple"><br><br>
<input type="text" value="orange"><br><br>
<button type="button">Clear red block!</button>
</div>
<div style="border: 2px solid green; margin: 10px"">
<input type="text" value="pizza"><br><br>
<input type="text" value="burger"><br><br>
<button type="button">Clear green block!</button>
</div>
</body>
</html>

Read more: jQuery Selectors[^]
 
Share this answer
 
v2
Comments
J{0}Y 30-Jan-15 1:29am    
it is working. But i want a function in c# which is clear all textbox
Peter Leow 30-Jan-15 2:46am    
Clearing textboxes using code behind incurs a round trip to the server and back. Just do it on the browser using jQuery.
J{0}Y 30-Jan-15 4:13am    
yes, You are Right

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