ALL TEXT SELECTION IN HTML TEXTBOX USING JAVASCRIPT

Ankita Pandey

Total Post:183

Points:1285
Posted by  Ankita Pandey
 1409  View(s)
Ratings:
Rate this:

I'm creating an application in HTML and I want to select all text in webpage textbox using JavaScript.

  1. Vijay Shukla

    Post:100

    Points:700
    Re: all text Selection in HTML textbox using javascript

    that code will help you for solving your problem.

    <html>
    <head>
    <script type="text/javascript">
    function allSelection(val, id) {
            document.getElementById(id).value = val.replace('$', '');
            val = document.getElementById(id).value;
            var ctrl = document.getElementById(id);
            pos = ctrl.value.length;
            ctrl.setSelectionRange(0, pos);
        }
    </script>
    </head>
    <body>
    <input type=='text' id='t1' value="AllSelection" onclick='allSelection(value, id)'/>
    </body>
    </html>

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!