How can I "get" the contents that are typed into a input on a form and place them in a element? The example below works on html elements but doesn't seem to work on input. Do I have to "action=post" the contents to make them accessible?
Ok lets say someone doesn't fill in a
certain form input, and the "val" would end up to be "[object
HTMLInputElement]". Best thing to do would be make an "if input is
empty, ignore it" type of statement?
What are your thoughts on something like this instead? It should bring my code size down, because I have quite a few inputs on this form. (22 is number of characters that var year would have if input wasn't filled out.)
var year = '<p><strong>' + $('#year').val() + '</strong> -';
((year.length > 22)? 'yes' : alert('Please fill in Year'));
If you want to save lines, then just modify Jay's initial code a little bit:
var year = '';
if($('#year').val().length > 0) {
var year = '<p><strong>"' + $('#year').val() + '"</strong> - ';
}
That'll save you a couple of lines.
Your way, like Jay said, doesn't make much sense and adds unnecessary overhead to he entire process. Sure it most likely wouldn't be noticeable to the user but why do it if you don't have to.
Leave a comment on dsvick's reply
Change topic type
Link this topic
Provide the permalink of a topic that is related to this topic