to infinity I have an input number that I want to store in integers. If the value becomes ...">

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

I have an input number that I want to store in integers. If the value becomes negative, then I want the displayed character to be ∞ ( &#8734;).

Doing this does not work (a space is displayed instead of "∞"):

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

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

+4
source share
2 answers

What are your requirements for having a number field? Can you rely on form validation and use Javascript to gradually improve just a set of numbers. Then use something like this

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

(pattern , )

+1

text CGI::unescapeHTML

<% 
   if foo <= -1
     v = CGI::unescapeHTML('&#8734;')
   else
     v = foo
   end
%>
<input type="text" value="<%= v %>">
0

Source: https://habr.com/ru/post/1534888/


All Articles