Click here to Skip to main content
15,884,237 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I had HTML like this:

<div class="floatleft">
  <h2>Add a Job/Location</h2>
  <form>
    <label for="jobLoc">Designation for Job/Location</label>
    <input type="text"  id="textJobLoc" name="textJobLoc" autofocus>
    <input type="submit"  id="insertJobLoc" name="insertJobLoc" value="Save Job/Location">
  </form>
</div>


...but then thought I didn't/need want the form submit behavior and used an HTML button instead of an input element of type submit:

<div class="floatleft">
  <h2>Add a Job/Location</h2>
    <label for="jobLoc">Designation for Job/Location</label>
    <input type="text"  id="textJobLoc" name="textJobLoc" autofocus>
    <button type="button" id="btnSaveJobLoc" name="btnSaveJobLoc">Save Job/Location</button>
</div>


But since it's now not a "form submit", does retaining the "form" tags make any sense? Does it harm/help anything to retain/remove the "form" tags?
Posted

1 solution

No there is no point keeping the form tag in the HTML if you are not using the Form Submit. You can put everything inside a div and on the clock event You can retrieve the data and send it to the server.

But using form elements have their own advantages. It makes life a lot more easier. Its easier to collect the form data with new Form() object. If you dont want to submit the form you still can do that by preventing the default behavior of Form Submit.

JavaScript
$('form').submit(function(e){
    e.preventDefault(); //This prevents the form being submitted
    //Then your code goes here...
    // .......................................

});


Hope this helps.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900