Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reset button not working in html (php)

Tags:

html

php

I have placed my input type reset button inside form but its still not working.

<form method='post' action='process/update_news_action.php' >
<tr>
   <td colspan='2' class="col-md-4">Update News Content</td>
</tr>
<tr >
   <td colspan='2' class="col-md-8"><textarea name="news" id="text"><?php echo  $rows["news"] ;  ?></textarea></td>
</tr>
<tr>
   <td class="col-md-4"><input name='submit' type="submit" value='Publish' class="btn btn-success" /></td>
   <td class="col-md-4"><input name='reset' type="reset" value='Reset' class="btn btn-primary" /></td>
</tr>
</form>

I have also tried <button type="reset" value="Reset">Reset</button>

like image 888
Jaspreet Kaur Avatar asked Nov 22 '16 06:11

Jaspreet Kaur


People also ask

How do I get the reset button to work in HTML?

Using reset buttons<input type="reset"> buttons are used to reset forms. If you want to create a custom button and then customize the behavior using JavaScript, you need to use <input type="button"> , or better still, a <button> element.

How do you reset input in HTML?

The <input type="reset"> defines a reset button which resets all form values to its initial values.

Why do we use type reset in a button tag?

The reset button is used to reset all the input fields in HTML forms. It gets added using the <input> tag attribute type.


1 Answers

If you're expecting the reset button to empty out the form, that's not the way reset works. It will reset the form fields to what they were when the page was loaded. In this case, you have pre-filled content in your form, so clicking reset will simply undo any user changes since the page-load.

To reset all form fields to blank/nothing, you will need javascript. First get the form DOM object, then iterate over all the input types you want to reset, and set each field.value = '' (input text types / textarea), or modify attributes (for select, radio, checkbox etc.) to deselect and so on. Turn that into a function (there's probably a ready piece somewhere out there, I seem to have lost mine), and set it up for your reset button's onclick (and return false unless you want the default action to run too).

Edit: On a quick search, here's a basic example of how to clear a form to empty values.

like image 152
Markus AO Avatar answered Sep 28 '22 01:09

Markus AO