0

Good Morning

I am trying to set an input field to have max length of 4 characters to use as a year field (YYYY).

I have read many posts on this forum the last couple weeks but have additional issues that i need to overcome, from what I have read I don't think I can do it but I am hoping someone can confirm this so I don't waste another dozen plus hours trying.

I am using the program survey anyplace to design a survey, this allows you to upload css files and i know what I am trying to do cannot be done in css.

The HTML of the field I am trying to do this to is.

<input id="answer-1264843-4103251" class="input form-item-answer" type="text" maxlength="100" name="question-1264843" value="" data-order="1" data-id="4103251" data-type="text">

However, I am not able to change the HTML, as a user we don't have the access. You can only access a code view which allows html for the question you are creating but not the answers. All other html cannot be accessed.

I did try this code found in another thread as a last resort, which didn't work.

{
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 4ch;
}

Found here: Setting a max character length in css

I also tried using java script and inserting the script tag but as soon as i type it, the code disappears and as I don't have access to the HTML I cannot put it in the head.

$(document).ready(function () {
    $("#answer-1264843-4103251").attr('maxlength', '5');    
});

<script type="text/javascript" src="//file name.js" />

Found here: (currently looking for the thread I found this on, will update when found)

I hope this question is enough to create a new thread, as I have tried solutions from a range of other threads and wasn't sure if i should of piggy backed on one of them.

Any guidance would be much appreciated. If you need any more info please ask.

Toby
  • 25
  • 5
  • 1
    Unfortunately there is no way to actually limit characters with CSS, you can make it look like it's limiting them but it can't actually force 4 characters, you have to either be able to add javascript to change the attribute or change the html. – Matthew T Rader Mar 29 '19 at 03:23
  • 1
    Thanks I thought that was the case just wanted to get someones else's opinion, thanks. – Toby Mar 29 '19 at 06:31

0 Answers0