Home > DeveloperSection > Forums > all text Selection in HTML textbox using javascript
Ankita Pandey
Ankita Pandey

Total Post:183

Points:1285
Posted on    December-06-2012 12:34 AM

 JavaScript JavaScript 
Ratings:


 1 Reply(s)
 1112  View(s)
Rate this:

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



Vijay Shukla

Total Post:100

Points:700
Posted on    December-06-2012 8:08 AM

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>


Don't want to miss updates? Please click the below button!

Follow MindStick