Reset Button Doesn't Clear the Element

Can anyone help me with fixing my code problem?

When I click my reset button, I want the sales tax rate percent displayed in the span id inside the p tag be removed

	<form id="form1" name="form1" method="post" action="">
		<p>Please select a state:
		<select name="selectState" id="selectState" onchange="salesTaxLookup()">
			<option>Please select a state</option>

	<p>The sales tax rate is: <span id="displayTaxRate" reset()></span></p>

	<!-- <p>
		<input type="reset" name="button2" id="button2" value="Reset"/>
	</p> -->

	<button type="reset" value="formreset" onclick="clearForm()">Reset</button>


	var states =new Array();  // this creates array for states
	states[0] = "Iowa";
	states[1] = "Illinois";
	states[2] = "Missouri";
	states[3] = "Wisconsin";

	var stateSalesTax = new Array();
	stateSalesTax[0] = "7%";
	stateSalesTax[1] = "11%";
	stateSalesTax[2] = "7%";
	stateSalesTax[3] = "8%";

	var count;
	count = 1;
	while(count <= 4)
		var option = document.createElement('option');

		option.text = states[count - 1];
		document.getElementById("selectState").add(option, count); 


	function salesTaxLookup(){
		for(i = 0; i <= 3; i++){
			var selectState = document.getElementById("selectState");
			if(states[i] == selectState.options[selectState.selectedIndex].text){
				displayTaxRate.innerHTML = stateSalesTax[i];

	function clearForm(){
	// I don't know what to put in here to fix my problem. I have tried several techniques but it doesn't work 


In your

 function clearForm(){
  var pTag = document.querySelector('#displayTaxRate');
  this.pTag = '';

I think you can do this way.

I was hoping it would work this way but it still doesn’t work. Thanks for trying to help.

I really confess I get curious with your problem… So I found your solution :smiley:

      function clearForm() {
        var pTag = (document.getElementById('displayTaxRate').innerHTML = '');

This way, your reset button just clear the value you have there.

Hope it helps you!

Yes, it works now. Thank you very much.

1 Like