Javascript createTextRange (); question
After an error warning, the next line gives the error. How can I fix this with javascript or jquery?
for(var nI = 0; nI < aOrderNumList.length; nI++) {
if(!isEmpty(aOrderNumList[nI])) {
alert("Invalid Order Number");
var oTextRange = $("#OrderNumList").createTextRange();
var lFound = oTextRange.indexOf(aOrderNumList[nI])!=-1;
if(lFound) {
oTextRange.select();
}
return false;
}
}
Html code
<tr>
<td>Order Number List:</td>
<td><textarea tabindex="<%=nIndex+1%>" id="OrderNumList" name="OrderNumList" rows="2" cols="35" <%=VClass("OrderNumList","")%>></textarea></td>
</tr>
Many thanks.
+3
source to share
3 answers
As in the code, you need to select the text content of the input element (text, type input text fields).
Java Script
document.getElementById("selector").select()
//selector is element id
JQuery
setTimeout(function () {
$("#selector").select();
}, 1);
//selector is element id, also can you with class selector ie. $(".selector").select();
+2
source to share
I think it should be:
var oTextRange = $("#OrderNumList")[0].createTextRange();
createTextRange is a method of a DOM object, not a jquery object.
Update:
The createTextRange method is supported by body, button, textarea, and input elements, but using the method throws an exception for some input elements (checkbox, image, radio). The isTextEdit property can be used to throw an exception.
see more: http://help.dottoro.com/ljfahrpo.php
+1
source to share