silder control or number - html

I was searching for answer for this question
You are developing an HTML5 web form to collect feedback information from site visitors. The web form must display an INPUT element that meets the following requirements:
Allow numeric values between 1 and 10.
Default to the value of 5.
Display as a slider control on the page. You need to add the INPUT
element to the form.
Which HTML element should you add?
<input type="number" name="rating" min ="1" max-"10">
<input type="number" name="rating" min="1" max="10" default="5">
<input type="range" name="rating" min="0" max="10" default"="5">
<input type="range" name="rating" min="10" max="10" value="5">
Shouldn’t the answer be this one.
<input type="range" name="rating" min="0" max="10" default"="5">

There appears to be a lot of confusion regarding this question.
Let's break down the requirements:
Allow numeric values between 1 and 10 : type="number" min="1" max="10"
Default to the value of 5 : This is defaulted by value = 5
Display as a slider control on the page : input type="range"
As you can see, numeric and slider are conflicting with each other. You can have a slider or you can have a numeric input box, not both.
I would assume that the question is asking for a slider, and so the value="5" field would put the slider in the middle.
The answer is
<input type="range" name="rating" min="10" max="10" value="5">
(there is a typo for min="10", should be min="1" but this is the correct answer for this question).

Related

Setting min and max on input removes spacing?

For some reason, when I set min and max values on an input like so:
<p>The placeholder of the second input is cut off (i.e. input is collapsed) when the input is assigned a min and max value?</p>
<input type="number" placeholder="This is my placeholder.">
<input type="number" placeholder="This is my placeholder." min="1" max="15">
The input collapses into a small space:
Example
I'd like to prevent this from happening without having to set a "width" value on the input. Is this possible?
Thanks!
The browser is rendering the <input type="number" /> to the size that will fit its maximum content:
<label for="99">Max is 99</label>
<input name="99" id="99" type="number" min="1" max="99">
<br/>
<label for="99">Max is 999</label>
<input name="99" id="99" type="number" min="1" max="999">
<br/>
<label for="99">Max is 9999</label>
<input name="99" id="99" type="number" min="1" max="9999">
<br/>
<label for="99">Max is 99999</label>
<input name="99" id="99" type="number" min="1" max="99999">
<br/>
<label for="99">Max is 999999</label>
<input name="99" id="99" type="number" min="1" max="999999">
If you want to enter some placeholder value that exceeds that content, you'll have to resize it with CSS; the size and width attributes are not valid for the "number" type.
Also, as A Haworth points out in the comments, the usefulness of the placeholder here is rather limited-- in fact, I would challenge that perhaps placeholders are of rather limited benefit generally. Consider that if this text is important enough to be on the page, it is important enough to be displayed as part of the label, where it is always visible and of sufficient contrast that it can be easily seen and read.

How to get HTML 5 input type range with string values

I need HTML 5 slider with three text value instead of integer. for example one I need following three value in slider.
likely
unlikely
very likely
<input type="range" min="1" max="100" value="50" class="slider" id="myRange">
This would give you the HTML input you want:
<input type="range" min="1" max="3" value"1" class="slider" id="myRange">
From there you could put text above/below it for display purposes. You'd simply save the integer as a value, or change it to text server-side.

Adding a slider to html

I want to add a slider as in input on a web page I am designing. I don't even know if it is called a slider.
A "slider" is written like this but within <> tags:
<input type="range" min="5" max="10" step="0.01">
You can set step to 1 and set the minimum and maximum values however you want.
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/range
If you're looking for two sliders, you can build it out of two sliders like this:
<input value="500" min="500" max="50000" step="500" type="range">
<input value="50000" min="500" max="50000" step="500" type="range">
https://codepen.io/rendykstan/pen/VLqZGO

Number input halves in size when using min and max

When making an input, like so:
<input type="number" min="0" max="100"><br>
<input type="number" min="0" max="99"><br>
<input type="number" min="1" max="100"><br>
<input type="number" min="1" max="99"><br>
It shortens the width of the input field, specifically when max is at 100. Since i've never seen this, i can only guess it does this thinking i will use percentages or currency, which i actually do, but i do not want this. Is there another way to prevent this from happening besides using different values or changing the size of the input yourself?
This is the default behaviour of how some* browsers render those inputs. So the answer is No. If you want to have certain width, take a look at the other answers.
* Different browsers render elements differently:
And this is the result of your snippet in Mozilla Firefox:
The input field width adapts to the width of the highest value: 100. 99 has one less character, so the input field is shorter. I don't think you can prevent that difference without CSS if your max values have a different character length.
Now, CSS should be a piece of cake....
<style>.medium-input {width:100px;}</style>
<input type="number" min="0" max="100" class="medium-input"><br>
<input type="number" min="0" max="99" class="medium-input"><br>
<input type="number" min="1" max="100" class="medium-input"><br>
<input type="number" min="1" max="99" class="medium-input"><br>
I'm adding the same class to all of the inputs, so that you can also define some other lengths if you like.
You could also do it with input[type=number] as a selector.
you can add css to control the width of inputs.
this will do the job :
input[type=number]{
width: 150px;
}

input number max attribute resizes field

When adding a max value to an input number field in Chrome, it will re-size the field according to width of highest value.
It seems that I cannot control the re-sizing behavior.
<input type="number" name="" value="3500" placeholder="3500" min="500">
<br>
<input type="number" name="" value="3500" placeholder="3500" min="500" max="100000">
<br>
<input type="number" name="" value="3500" placeholder="3500" min="500" max="100000000">
Question: How can I make it behave like without max attribute or a normal text field.
PS: I cannot see any changes in the styles when switch the type.
PPS: I must say that I already tried using -webkit-appearance: textfield; but Chrome was already using textfield by default.
Solution with percentage and div
Although it's been almost 6 years since this question was posted, just a few minutes ago I found myself in the same situation as the OP. The solution is to add a div that acts as a container for the input field. Then to the width of the input we add the rule for fill all the available space and at this point we can just change the size of the div wrapper as desired.
The first two inputs show what happens without div. The last two inputs have the same size despite the different 'max' value.
p{margin-bottom: 0;}
.wrapped{
width: -moz-available;
width: -webkit-fill-available;
width: fill-available;
}
.inputWrapper{width: 30%;}
<p>Min 0, max 10</p>
<input type="number" min="0" max="10">
<p>Min 0, max 1000000</p>
<input type="number" min="0" max="1000000">
<div class="inputWrapper">
<p>Wrapped: min 0, max 10</p>
<input class="wrapped" type="number" min="0" max="10">
<p>Wrapped: min 0, max 1000000</p>
<input class="wrapped" type="number" min="0" max="1000000">
</div>
About the auto-resize of the input field
I honestly didn't read what the documentation says about this automatic resize and I was surprised when I noticed this unexpected and undesired behaviour. From the following simple tests we can see that the resize occurs only if both values 'min' and 'max' are set: the resize seems to be proportional only to the distance between max-0 instead of the distance max-min. Note that this is the default behavior without the proposed solution.
p{margin-bottom:0;}
<p>Min 0</p>
<input type="number" min="0">
<p>Min 100</p>
<input type="number" min="100">
<p>Max 0</p>
<input type="number" max="0">
<p>Max 100</p>
<input type="number" max="100">
<p> The previous input fields have the same width<p>
<p>Min 0, max 10</p>
<input type="number" min="0" max="10">
<p>Min 0, max 100</p>
<input type="number" min="0" max="100">
<p>Min 99, max 100</p>
<input type="number" min="99" max="100">
Simply set a width for input.
input {
width: 100px;
}
for example.