Solved

Define differeing numerical value for input

Posted on 2013-12-02
4
255 Views
Last Modified: 2013-12-03
I'm trying to create a calculator which can determine someones snowboard length primarily by their body weight. I had a <select> tag initially but to improve user experience I'm attempting to have an <input> tag where they can just enter their body weight within the parameters of 13 to 113. I cant seem to find any way to get this input field where I can also provide each number given with a value via an <option> tag. Here is the code I'm using so far...

<td style="padding-right: 80px; margin-bottom: 15px;"><strong>Body Weight</strong></td>
<td>
<input id="weight" name="weight" type="number" style="margin-bottom: 15px; width: 40px; padding: 5px; text-align: right; padding-right: 5px;"><span class="help-inline" style="color: #999; margin-bottom: 15px; margin-left: -3px;">kgs</span>
<option value="90">13</option>
<option value="90">14</option>
....
<option value="172">112</option>
<option value="172">113</option>
</td>
</tr>

Open in new window


Any alternatives which would also achieve the same outcome would also be fine. To recap and solidify my objectives with this area of the calculator:

Input text box which provides a different value depending on the number entered.
A minimum of 13 and maximum 113 which can be entered.

Any help or quick suggestions on this would be greatly appreciated as I can't seem to jump this hurdle alone.

Thanks
0
Comment
Question by:MaxP0wers
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 11

Expert Comment

by:Angelp1ay
ID: 39689809
Hi MaxP0wers

As far as I'm aware there is no HTML only option which allows text entry AND limits the options.

You could use the select tag instead (see http://www.w3schools.com/tags/att_select_form.asp):
<select name="carlist" form="carform">
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="opel">Opel</option>
  <option value="audi">Audi</option>
</select>

Open in new window


...or I guess you could use javascript (probably jquery) to show a warning for invalid entries.
0
 
LVL 43

Accepted Solution

by:
Chris Stanyon earned 250 total points
ID: 39689810
An <option> tag has to be wrapped inside a <select> tag, which creates a dropdown.

Your <input> tag is set to a type of 'number' which is HTML5 and doesn't work in Firefox.

If you're looking at improving the user experience, why not take a look at the jQueryUI library - they offer a slider that may do precisely what you need.

Have a play with this to see it in action (just slide the slider)

http://jsfiddle.net/ChrisStanyon/JgxWx/
0
 
LVL 11

Expert Comment

by:Angelp1ay
ID: 39689826
This looks promising :)
http://jqueryvalidation.org/min-method#value
http://jqueryvalidation.org/max-method#value

$( "#myform" ).validate({
  rules: {
    field: {
      required: true,
      min: 13,
      max: 113
    }
  }
});

Open in new window

0
 
LVL 11

Expert Comment

by:Angelp1ay
ID: 39689829
Actually I prefer Chris' answer, +1 to the slider :)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question