1

Sir I am using these codes to clear all textboxes in form

<script type="text/javascript" src="jquery-1.7.1.min.js">
function clearboxes()
{
    document.getElementById("my_name").value="";
    document.getElementById("my_moba").value="";
    document.getElementById("my_mobb").value="";
    document.getElementById("my_add").value="";
    document.getElementById("my_email").value="";
    document.getElementById("my_myfax").value="";
        document.form1.my_name.focus() ;
}
</script>

Is there any way to run loop to clear all textboxes rather then writinng separte line for every textbox?

3
Contributors
3
Replies
21
Views
3 Years
Discussion Span
Last Post by Troy III
2

Here is a very simple example without a loop.

<!DOCTYPE html>
<html>
<head>
 <title>Demo</title>
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>

</head>
<body>

<input type="text" id="txtBox1" /><br/>
<input type="text" id="txtBox2" /><br/>
<input type="text" id="txtBox3" /><br/>
<input type="text" id="txtBox4" /><br/>
<input type="text" id="txtBox4" /><br/>
<button id="btn1">Clear</button>

<script>
$('#btn1').click(function(){
  $('input').val("");
});
</script>

</body>
</html>
2

here is it with a loop...

<script>
$('#btn1').click(function(){
  $('input').each(function(index) {
    $(this).val("");
  });
});
</script>

Edited by JorgeM

2

Sir I am using these codes to clear all textboxes in form

Have you tried the reset button?

<form...>
.
.
.
<button type="reset" value="reset">clear</button>
</form>

or scripting:

document.forms[0].reset();
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.