The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> clear button code is not working in html
shankar from vizag
post Jul 4 2013, 03:35 AM
Post #1


Advanced Member
****

Group: Members
Posts: 173
Joined: 18-June 13
Member No.: 19,316



Hai everyone

I am having an HTML page containing two columns table, on left side it contains lable names and on the right column I placed text boxes relating to the left label names. I placed a button namely CLEAR. The main purpose is to clear off the text boxes value at a single click.

On the head section, I had given the following function
<script>

function clearForm() {

document.TextBox3.value="";

document.TextBox4.value="";

document.TextBox5.value="";

document.TextBox6.value="";

}

</script>

and at the body section, I had given the following line for the button

<input type='button' onClick='clearForm()'value='Clear Fields'/>

which is not working in realtime operation.

kindly help me.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
rhysowen
post Jul 4 2013, 03:45 AM
Post #2


Newbie
*

Group: Members
Posts: 19
Joined: 2-July 13
Member No.: 19,368



CODE
<script>
        function clearForm(){
            document.getElementById('TextBox3').value = '';
            document.getElementById('TextBox4').value = '';  
            document.getElementById('TextBox5').value = '';
            document.getElementById('TextBox6').value = '';          
        }
</script>

<input type="button" onClick="clearForm()" value="Clear Fields" />


smile.gif Try That

Rhys (readthisblogonline.co.uk)

This post has been edited by rhysowen: Jul 4 2013, 03:46 AM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Frederiek
post Jul 4 2013, 04:30 AM
Post #3


Programming Fanatic
********

Group: Members
Posts: 5,146
Joined: 23-August 06
From: Europe
Member No.: 9



Or:
Javascript can't find the textbox like that using document.TextBox3.value. It needs a reference to the form name.
Say you use <form name="test"> (as I did in another thread by you), then you can use:
document.test.TextBox3.value=""; for all text fields to be cleared.

And correct the input like this:
<input type="button" onclick="clearForm();" value="Clear Fields">
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
rhysowen
post Jul 4 2013, 06:35 AM
Post #4


Newbie
*

Group: Members
Posts: 19
Joined: 2-July 13
Member No.: 19,368



@"shankar from vizag":

How are you naming your textboxes? With the name tag, id tag, etc?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
shankar from vizag
post Jul 4 2013, 11:28 PM
Post #5


Advanced Member
****

Group: Members
Posts: 173
Joined: 18-June 13
Member No.: 19,316



QUOTE(rhysowen @ Jul 4 2013, 02:15 PM) *

CODE
<script>
        function clearForm(){
            document.getElementById('TextBox3').value = '';
            document.getElementById('TextBox4').value = '';  
            document.getElementById('TextBox5').value = '';
            document.getElementById('TextBox6').value = '';          
        }
</script>

<input type="button" onClick="clearForm()" value="Clear Fields" />


smile.gif Try That

Rhys (readthisblogonline.co.uk)



tons of thanks for supporting me.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
shankar from vizag
post Jul 10 2013, 01:10 AM
Post #6


Advanced Member
****

Group: Members
Posts: 173
Joined: 18-June 13
Member No.: 19,316



QUOTE(rhysowen @ Jul 4 2013, 05:05 PM) *

@"shankar from vizag":

How are you naming your textboxes? With the name tag, id tag, etc?



Thank u so much rhysowen, its working.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 5th August 2020 - 12:34 AM