create Range for Other browsers (Cross Browser Compatibility)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Suganthar
    New Member
    • May 2012
    • 6

    #1

    create Range for Other browsers (Cross Browser Compatibility)

    I have a text box. When I write first text , then java script function will fire to check whether it is a number.

    For IE , the following code is returning -1 value, But Other browsers it does not alert any value. Please help me

    Code:
    var selected = document.selection.createRange();
    
    var decInSel = selected.text.indexOf('.');
    hasNegInSel  = selected.text.indexOf('-') != -1;
    
    alert(decInSel);
    Last edited by Dormilich; May 21 '12, 06:56 AM. Reason: Please use [CODE] [/CODE] tags when posting code.
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    reason is probably that IE & other browsers use a slightly different Range model.

    Comment

    • Suganthar
      New Member
      • May 2012
      • 6

      #3
      Please help me how i can modify this to work in other browsers

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        since I haven’t used Ranges myself, I can only point you to the appropriate references (MDN). (make sure to also check the links given there)

        Comment

        Working...