0

How to Resize <input>

How do you restrict the number of characters that can be entered and how to change width and height? I tried using the attributes width and height Please Help!!

8th Jul 2017, 7:23 PM
Mame86
Mame86 - avatar
17 Respuestas
+ 4
Yes: you could even put the body function directly inlined in the 'oninput' attribute ;)
8th Jul 2017, 8:22 PM
visph
visph - avatar
8th Jul 2017, 8:04 PM
visph
visph - avatar
8th Jul 2017, 8:16 PM
visph
visph - avatar
+ 2
<input type='text' maxlength='10' style='width:200px;height:50px;'>
8th Jul 2017, 7:27 PM
Yasiru Nayanajith
Yasiru Nayanajith - avatar
+ 2
It should work... and works for me: are you sure to not have some typo mistake? What's your context (browser, os, versions)?
8th Jul 2017, 7:46 PM
visph
visph - avatar
+ 2
I tried it and it seems to work only with numbers, not letters... weird
8th Jul 2017, 7:48 PM
Russel Reeder
Russel Reeder - avatar
+ 2
@Russel Reeder: It works as well with digit as with letters ^^ @Mamex86: I cannot try it on desktop (I'm on mobile and don't have desktop near of me)... but actually on Android Samsung internet browser (probably based on Chrome) it works... What OS? Wich version of each? These informations are essential to study the same context (in case of some bug linked to a particular version ^^) And could you copy-paste your code, to verify your syntax? ;)
8th Jul 2017, 7:57 PM
visph
visph - avatar
+ 2
First answer of the linked thread suggest a workaround with 'min' and 'max' attribute values... but it's fail too ^^ I don't have read the whole thread, so I suggest you to first read it entirely and test proposed solution ;) Anyway, what I would do, would be to set the 'oninput' event listener with a function validating input on the fly, and doesn't allow more than n char (by updating the 'value' attribute value with last entry (before reaching the limit) or by truncating the value to the max length expected ^^
8th Jul 2017, 8:10 PM
visph
visph - avatar
0
doesn't work
8th Jul 2017, 7:29 PM
Mame86
Mame86 - avatar
0
Now it works ^^
8th Jul 2017, 7:31 PM
Mame86
Mame86 - avatar
0
but maxlength doesn't work
8th Jul 2017, 7:33 PM
Mame86
Mame86 - avatar
0
visph. I am running in Chrome.
8th Jul 2017, 7:49 PM
Mame86
Mame86 - avatar
0
For me, maxlength works when your type is set to 'text'. But when you set it to 'number' it fails to restrict the number of characters
8th Jul 2017, 7:53 PM
Mame86
Mame86 - avatar
0
I am on Chrome 58.0.3029.81 (64-bit) Windows 8.1 https://code.sololearn.com/WL2999KjTtq1/?ref=app
8th Jul 2017, 8:03 PM
Mame86
Mame86 - avatar
0
Right what should I use then?
8th Jul 2017, 8:05 PM
Mame86
Mame86 - avatar
0
Ok Thank you. I always like looking for the solution with built-in html first. I feel that there is a workaround for it in raw html. Thank you for your idea though. Greatly appreciate your time
8th Jul 2017, 8:16 PM
Mame86
Mame86 - avatar
0
Cool That's perfect and it's just a few lines ☺
8th Jul 2017, 8:20 PM
Mame86
Mame86 - avatar