user17631451
user17631451

Reputation:

Should 'form' be used here, or is it not necessary?

Should form be used in this code, or no?

Form Added https://jsfiddle.net/t6nsygvd/6/

<div class="info">
  <form>
    <label for="input">Stream</label>
    <input id="input" type="text" name="someNameHere" value="http://hi5.1980s.fm/;" />
    <input id="sent" type="submit" value="Set" />
  </form>

sent.addEventListener("click", function(evt) {
    player.src = value.value;
    player.volume = 1.0;
    // Prevent default form handling (which would reload the page, in this case)
    evt.preventDefault();
  });
}());

Form Removed: https://jsfiddle.net/t6nsygvd/7/

<div class="info">
    <label for="input">Stream</label>
    <input id="input" type="text" name="someNameHere" value="http://hi5.1980s.fm/;" />
    <input id="sent" type="submit" value="Set" />
</div>

  sent.addEventListener("click", function(evt) {
    player.src = value.value;
    player.volume = 1.0;
  });

Upvotes: 0

Views: 43

Answers (2)

cvekaso
cvekaso

Reputation: 865

I think not. You are not submitting anything, you are just calling other provider to start play.

Upvotes: 0

Terry
Terry

Reputation: 66123

<form> should be used when you want to submit an entire set of data somehow to the server. The advantages of using form is that you have access to the form API (such as the submit event), and that you can perform serialization of all user inputs in the element. However, in this case, you are simply capturing individual user inputs, so there isn't a need to use it.

Upvotes: 2

Related Questions