I have a page in mvc where I have 4 textbox with id and i want to clear the textbox on button click but my code does not seem to do any thing. Here’s my piece of code:
<td><%: Html.TextBoxFor(model => model.fdose, new { id = "pls", style = "width:100px;" })%> </td>
<td><%: Html.TextBoxFor(model => model.fduration, new { id = "plss", style = "width:100px;" })%></td>
<td> <button type="submit" class="t-button" name="med" value="med" id="clearmed">+</button></td>
And here’s my script:
$("#clearmed").click(function (event) {
$("#plss").val("");
$("#pls").val("");
$("#abc").val("");
$("#abcd").val("");
});
Since it is a submit button, prevent the default behaviour of the submit button, on click. You can use
preventDefaultmethod to do that. Also wrap your code in the ready event.