Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML how to set value of <input type="number"> to infinity

I have a number input that I want to hold integers. If the value gets set to negative then I want the symbol shown to be ∞ (&#8734;).

Doing this doesn't work (a blank is shown instead of "∞"):

<%
if foo <= -1
    v = '&#8734;'
else
    v = foo
end
%>
<input type="number" value="<%= v %>">

Is there a way to do it without resorting to javascript?

like image 833
erapert Avatar asked Apr 03 '14 17:04

erapert


1 Answers

What are your requirements for having a "number" field? Can you rely on form validation and use Javascript to progressively enhance just typing numbers. Then use something like this

<input type="text" pattern="([0-9]|&#8734;)+">

(pattern will prevent the form from submitting unless it's a number or infinity symbol)

like image 119
Akurn Avatar answered Oct 08 '22 18:10

Akurn