I don’t like to disagree with you but enclosing form elements in paragraph elements is fully allowed, and is even recommended in the HTML specs. See, Writing a forms user interface
It’s been that way for at least HTML4 and HTML5.
Rather I was pointing out that it was semantically poor coding.
Of course, I do understand that totally ignoring semantics
seems to be the order of the day – with people wrapping
paragraphs around non-paragraph elements.
Why the W3C would advocate it’s use beggars belief.
Unfortunately, the cancer that is frameworks will eventually
destroy bespoke coding taking all semblance of semantics
with it.
So, until then, I will continue to suggest that if margins are
required for form elements then one should use a neutral
container such as the div element and apply appropriate
values to it in the CSS.
Ahh that is good. Your saying “should not be enclosed by the p element.” appeared to imply that it was not allowed.
All block-level elements are allowed as children of the form element, which includes fieldset, p, and div.
As the label element does supply text to the screen, that is an argument (though not my argument) for using p.
I also agree with you that using fieldset is the better way to format a form.
This discussion seems to be drifting a bit. For the record:
forms, I prefer fieldsets
frameworks, I think they’re best used for teams / frequent use.
Anyway, @waynecockfield because the code has = goodLuck() the function runs as soon as the browser loads the page. As you can see in coothead’s example, there is addEventListener( 'blur'
I think what can help you is to get a better understanding of “events”. There are lots and you may not want “blur” but I’m guessing you aren’t happy with the “load” event. This is a bit of a read but IMHO well worth the time spent
Maybe it’s worth mentioning that another problem is you can’t set the .innerHTML property of an input element as it doesn’t have any children – there’s no closing </input> tag for that reason. Furthermore, goodLuck() would run immediately and return undefined, which is why the alert shows right when you open the page. So your code is basically equivalent to
var phoneEl = document.getElementById('phone')
phoneEl.addEventListener('change', function () {
alert('Good luck')
})
However, note that using alert()s is not particularly good practice as it’s modal (i.e. it blocks the whole browser until the user clicked it away), and for this reason has been abused a lot by aggressive ads and worse, which again is why you can disable showing alerts altogether on a given page… so you can’t rely on that. Another problem is that you can’t apply any styles to it, so it will always stick out from your site’s design.
So if that alert() call is for debugging purposes only, use console.log() instead. If you want to actually show a modal box, it would be better to implement your own that only blocks the current page, not the entire browser… that’s not as difficult as it sounds, here’s a pen:
OT: Now this snippet is taken directly from the bootstrap docs: