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?

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>

here is it with a loop...

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

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();
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.