2 Replies - 251 Views - Last Post: 02 January 2013 - 10:00 PM

#1 The Architect 2.0  Icon User is offline

  • D.I.C Regular

Reputation: 37
  • View blog
  • Posts: 351
  • Joined: 22-May 08

using <input> elements without the <form> tag

Posted 29 December 2012 - 06:01 PM

Every once in awhile, I come across a situation where I want to by able to use various <input> elements, but they do NOT need to connect to the server.

Consider an html calculator. it obviously needs some sort of text input field and buttons, but it also obviously doesn't need a server to work.

what do I do then? I CAN make it work fine using JS, but how should the HTML itself be formatted? do I use a <form> tag and have it target nothing? or do I just omit it entirely?

EDIT:

I know i can just use <button> in lieu of submit <input>, but what about radio buttons, text inputs, etc.?

This post has been edited by The Architect 2.0: 29 December 2012 - 06:03 PM


Is This A Good Question/Topic? 0
  • +

Replies To: using <input> elements without the <form> tag

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3393
  • View blog
  • Posts: 9,591
  • Joined: 08-June 10

Re: using <input> elements without the <form> tag

Posted 29 December 2012 - 06:07 PM

if there is no <form> tag, there is nothing you can submit from.

if you’re going to use a <form> tag, be sure to disable submitting (though that needs JS to work (well, no submit button would be a good choice as well), with JS disabled it will submit, no matter what).
Was This Post Helpful? 0
  • +
  • -

#3 fiddydips  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 20
  • Joined: 02-January 13

Re: using <input> elements without the <form> tag

Posted 02 January 2013 - 10:00 PM

Well it's true, you don't really need a form tag. I once made a star field rotator program in javascript where I had several text input fields set to call a function onchange. I didn't put it inside of a form tag. You could also have a hyperlink that when clicked calls a function that reads the text input fields, makes a calculation, and updates the value or html of an element with the result of the calculation. You definitely don't need to wrap your input fields with form tags.

This post has been edited by Dormilich: 03 January 2013 - 05:53 AM
Reason for edit:: removed duplicate content

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1