Siva Charan
Siva Charan

Reputation: 18064

On ASP page, setting maxlength for the textbox field based on textbox size

I have a file "sample.asp" page.

<input type="text" name="ticker" id="ticker" value="<%=strTicker%>" size="107" />

On this text field, I have set size to 107.

How can I define the MaxLength based on size of textbox field?

First preference to English characters Second is for other language characters

Thanks in advance for the solution.

Upvotes: 0

Views: 1404

Answers (2)

George Cummins
George Cummins

Reputation: 28906

If you want to do it in ASP:

<%
Dim size
size = "107"
%>
<input type="text" name="ticker" id="ticker" value="<%=strTicker%>" size="<%=size%>" maxlength="<%=size%>" />

Upvotes: 0

George Cummins
George Cummins

Reputation: 28906

If you want to do it in Javascript:

<script type="text/javascript">
var ticker_element = document.getElementById("ticker");
ticker_element.setAttribute("maxlength", ticker_element.size
</script>

Upvotes: 1

Related Questions