EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: guruhyes on October 28, 2019, 05:46:51 PM



Title: [SOLVED]Selection js in jeasyui
Post by: guruhyes on October 28, 2019, 05:46:51 PM
Code:
<head>
    <script type="text/javascript">
        function Select (st,en) {
            var input = document.getElementById ("myText");
            if ('selectionStart' in input) {
                input.selectionStart = st;
                input.selectionEnd = en;
                input.focus ();
            }
            else {  // Internet Explorer before version 9
                var inputRange = input.createTextRange ();
                inputRange.moveStart ("character", 1);
                inputRange.collapse ();
                inputRange.moveEnd ("character", 1);
                inputRange.select ();
            }
        }
    </script>
</head>
<body>
    <input type="text" id="myText" value="Some text for testing"/>
    <button onclick="Select (2,4)">click me</button>
</body>
hai,
the code above is working when i use only javascript,
but when i change the text box to jeasyui the selection not working
Code:
<input type="text" id="myText" class="easyui-textbox" value="Some text for testing"/>
any solution?

sorry for bad english


Title: Re: Selection js in jeasyui
Post by: jarry on October 28, 2019, 08:25:27 PM
Please call 'setSelectionRange' method to select text on the textbox component.
Code:
$('#t').textbox('setSelectionRange', {start:2,end:4});
var range = $('#t').textbox('getSelectionRange');
console.log(range);


Title: Re: Selection js in jeasyui
Post by: guruhyes on October 29, 2019, 03:19:10 AM
Please call 'setSelectionRange' method to select text on the textbox component.
Code:
$('#t').textbox('setSelectionRange', {start:2,end:4});
var range = $('#t').textbox('getSelectionRange');
console.log(range);

hai Jarry,
thx for your reply,

i did what you suggested, but still not working
Code:
<input name="t" id="t" style="width:300px" type="text" class="easyui-textbox">
<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="dbu()">test</a>
<script>
function dbu(){
        $('#t').textbox('setSelectionRange', {start:2,end:4});
           var range = $('#t').textbox('getSelectionRange');
           console.log(range);
        }
</script>

console output
Code:
{start: 0, end: 0}
and i read the documentation, and the method setSelectionRange and getSelectionRange didnt exist


Title: Re: Selection js in jeasyui
Post by: jarry on October 29, 2019, 08:11:22 PM
Please look at this example http://code.reloado.com/uqatas3/edit#preview. It works fine.


Title: Re: Selection js in jeasyui
Post by: guruhyes on October 30, 2019, 12:35:08 AM
Please look at this example http://code.reloado.com/uqatas3/edit#preview. It works fine.

my bad jarry,you might misunderstanding.

i edited my code below
https://jsfiddle.net/guruhyes/hy34j1b6/4/
reff from :http://help.dottoro.com/ljtfkhio.php

so i want to select words inside the text box using click button

when i try your code the console output only
Code:
{start: 2, end: 4}
but i want the words inside the text box


Title: Re: Selection js in jeasyui
Post by: jarry on October 31, 2019, 12:41:16 AM
Please look at this updated example http://code.reloado.com/uqatas3/2/edit#preview. It works fine.


Title: Re: Selection js in jeasyui
Post by: guruhyes on November 01, 2019, 09:46:41 PM
it works,
thx jarry