html-input

Hot to get incomplete datetime-local input values

混江龙づ霸主 提交于 2019-11-28 11:21:14
I have the following form on my page: <input id='startDate' type='datetime-local' step=1 name='startDate'> I use this code to get the value of the field: var start = $('#startDate').val(); My problem is that the value of the input field remains undefined until every part of it has been filled out, including hours, minutes, seconds, and AM/PM. I would like to be able to get a value from the form with as little as just the year selected. How can I go about doing this? I'm happy to zero out the values not filled out, but I can't figure out how to get the part of the datetime-local that the user

Thymeleaf - How to add checked attribute to input conditionally

眉间皱痕 提交于 2019-11-28 07:24:57
As you know, input component has an attribute, checked to whether mark the checkbox as enabled by default or not. <input type="checkbox" name="mycheckbox" checked="checked"/> To disable the checkbox by default, the checked exception should be declared. Is it possible to set checked attribute by a flag in Thymeleaf? According to the official thymeleaf documentation http://www.thymeleaf.org/doc/tutorials/2.1/usingthymeleaf.html#fixed-value-boolean-attributes th:checked is considered as a fixed-value Boolean attribute. <input type="checkbox" name="active" th:checked="${user.active}" /> Where user

Drop Down Menu/Text Field in one

若如初见. 提交于 2019-11-28 04:18:10
I'm working on building new site, and I need a drop down menu to select the amount of something in my site. But at the same time I need this drop down list to accept text. So if the client wants to choose from the drop down list then he can, also if the client want to enter the amount by text then he can also. As you can see I want to make it dual. For example: suppose there is an amount drop down menu, and its elements are (1,2,3); Suppose now that the client needs the amount to be 5 - this is his right - it does not exist in the drop down list, so the client now must enter the amount

Setting focus to a textbox when a function is called

有些话、适合烂在心里 提交于 2019-11-28 02:35:22
问题 I currently have a textbox in my aspx: <input type="text" id="myTextbox" value="" /> I was wondering if I could set the focus (put my cursor in that text box) every time my JavaScript method is called. I was hoping it would work along the lines of this: function setFocus() { document.getElementById("myTextbox").Focus(); } Any suggestions? 回答1: Invoke the lowercase .focus() function: function setFocus() { document.getElementById("myTextbox").focus(); } 回答2: Try this: function setFocus(id) {

Why is the default max length for an input 524288?

ε祈祈猫儿з 提交于 2019-11-27 23:00:56
The default maximum length for a HTML input ( <input type="text"> ) is 524288 characters. That seems like a very peculiar number, why was it chosen? Patrick Hofman According to the w3c the maximum value is unlimited: maxlength = number [CN] When the type attribute has the value "text" or "password", this attribute specifies the maximum number of characters the user may enter. This number may exceed the specified size, in which case the user agent should offer a scrolling mechanism. The default value for this attribute is an unlimited number. Despite that, I have noticed that in Chrome indeed

HTML 5 input type=“number” element for floating point numbers on Chrome

空扰寡人 提交于 2019-11-27 19:58:35
I need to have users enter floating point numbers, so I use the following element: <input type="number" name="my_number" placeholder="Enter number"/> Works great on Firefox, but Chrome complains that the number is not an integer when I try to enter a decimal. That's a problem for my case. If I enter a step attribute, then Chrome allows the floating point number: <input type="number" name="my_number" placeholder="Enter number" step="0.1"/> But then the problem is 0.15 can't be entered... The step doesn't appear to suit my needs. The W3C spec mentions floating-point numbers throughout the

When to use the disabled attribute vs the aria-disabled attribute for HTML elements?

吃可爱长大的小学妹 提交于 2019-11-27 17:10:49
问题 I'm trying to make a form accessible. Should I make my inputs have both disabled and aria-disabled attributes, or just one? <label for="textbox1">Input</label> <input id="textbox1" type="text" name="Text Box" disabled> Or like this? <label for="textbox1">Input</label> <input id="textbox1" type="text" name="Text Box" aria-disabled="true"> Or like this? <label for="textbox1">Input</label> <input id="textbox1" type="text" name="Text Box" aria-disabled="true" disabled> 回答1: I can take your

Fill input file form with JavaScript [duplicate]

梦想的初衷 提交于 2019-11-27 16:08:12
This question already has an answer here: How to set file input value when dropping file on page? [duplicate] 1 answer Dynamically set value of a file input [duplicate] 4 answers How to set a value to a file input in HTML? 8 answers Note: The answer(s) below reflect the state of legacy browsers in 2009. Now you can actually set the value of the file input element dynamically/programatically using JavaScript in 2017. See the answer in this question for details as well as a demo: How to set file input value programatically (i.e.: when drag-dropping files)? I need to fill an HTML form with

How to deal with browser differences with indeterminate checkbox

此生再无相见时 提交于 2019-11-27 13:40:25
问题 Primer: An HTML checkbox can be set as indeterminate , which displays it as neither checked nor unchecked. Even in this indeterminate state, there is still an underlying boolean checked state. When an indeterminate checkbox is clicked, it loses its indeterminate state. Depending on the browser (Firefox), it can additionally toggle the checked property. This jsfiddle illustrates the situation. In Firefox, clicking either of the checkboxes once causes them to toggle their initial underlying

Trigger action on programmatic change to an input value

情到浓时终转凉″ 提交于 2019-11-27 12:04:31
My objective is to observe an input value and trigger a handler when its value gets changed programmatically . I only need it for modern browsers. I have tried many combinations using defineProperty and this is my latest iteration: var myInput=document.getElementById("myInput"); Object.defineProperty(myInput,"value",{ get:function(){ return this.getAttribute("value"); }, set:function(val){ console.log("set"); // handle value change here this.setAttribute("value",val); } }); myInput.value="new value"; // should trigger console.log and handler This seems to do what I expect, but it feels like a