Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. document.selection - not working in firefox

document.selection - not working in firefox

Scheduled Pinned Locked Moved ASP.NET
question
7 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sekannak
    wrote on last edited by
    #1

    Hi, This is not firing in Mozilla firefox.. if (document.selection) { alert("abc"); } what is the equalant function for Firefox can u clear me plz..... Regards, kannak

    kannak

    P 1 Reply Last reply
    0
    • S sekannak

      Hi, This is not firing in Mozilla firefox.. if (document.selection) { alert("abc"); } what is the equalant function for Firefox can u clear me plz..... Regards, kannak

      kannak

      P Offline
      P Offline
      Prosanta Kundu online
      wrote on last edited by
      #2

      Hi See this link http://www.java2s.com/Code/JavaScript/HTML/UsingthedocumentselectionObject.htm[^] Cheers Prosanta Kundu

      S 1 Reply Last reply
      0
      • P Prosanta Kundu online

        Hi See this link http://www.java2s.com/Code/JavaScript/HTML/UsingthedocumentselectionObject.htm[^] Cheers Prosanta Kundu

        S Offline
        S Offline
        sekannak
        wrote on last edited by
        #3

        Hi, I tried that link ..its working fine in IE but not working in Firefox.. my problem is also like that ...the Javascript function is working in IE but not working in FIREfox regards, kannak.........

        kannak

        P 1 Reply Last reply
        0
        • S sekannak

          Hi, I tried that link ..its working fine in IE but not working in Firefox.. my problem is also like that ...the Javascript function is working in IE but not working in FIREfox regards, kannak.........

          kannak

          P Offline
          P Offline
          Prosanta Kundu online
          wrote on last edited by
          #4

          Hi Here is your code below

          Selection Test Page
          function foo() {
          

          var selObj = window.getSelection();
          alert(selObj);
          var selRange = selObj.getRangeAt(0);
          // do stuff with the range
          }

          Select some of the text in document. Select text and see the result.
          

          Cheers Prosanta Kundu

          S 1 Reply Last reply
          0
          • P Prosanta Kundu online

            Hi Here is your code below

            Selection Test Page
            function foo() {
            

            var selObj = window.getSelection();
            alert(selObj);
            var selRange = selObj.getRangeAt(0);
            // do stuff with the range
            }

            Select some of the text in document. Select text and see the result.
            

            Cheers Prosanta Kundu

            S Offline
            S Offline
            sekannak
            wrote on last edited by
            #5

            Hi, I will clearly explain my requirement , Listbox and textbox in my page..listbox having 5 rows...when i select any data from the listbox , the selected data should copied and pasted to the Textbox...for i use Javascript method ...its working fine in IE but not working in Firefox..the javascript method as follows..can u please check it out why its not working in Firefox.. function insertTextFun() { if (document.selection) { document.getElementById("<%= txtExprsn.ClientID %>").focus(); var sel = document.selection.createRange(); var varname = document.getElementById("<%= lsbFunction.ClientID %>"); sel.text = varname.options[varname.selectedIndex].text; } else if (txtExprsn.selectionStart || txtExprsn.selectionStart == '0') { var startPos = txtExprsn.selectionStart; var endPos = txtExprsn.selectionEnd; txtExprsn.value = txtExprsn.value.substring(0, startPos) + lsbFunction[lsbFunction.selectedIndex] + txtExprsn.value.substring(endPos, txtExprsn.value.length); } else { txtExprsn.value += lsbFunction[lsbFunction.selectedIndex]; } Am calling this function onclick method of the listbox.. Thanks in Advance, kannak.......

            kannak

            P 1 Reply Last reply
            0
            • S sekannak

              Hi, I will clearly explain my requirement , Listbox and textbox in my page..listbox having 5 rows...when i select any data from the listbox , the selected data should copied and pasted to the Textbox...for i use Javascript method ...its working fine in IE but not working in Firefox..the javascript method as follows..can u please check it out why its not working in Firefox.. function insertTextFun() { if (document.selection) { document.getElementById("<%= txtExprsn.ClientID %>").focus(); var sel = document.selection.createRange(); var varname = document.getElementById("<%= lsbFunction.ClientID %>"); sel.text = varname.options[varname.selectedIndex].text; } else if (txtExprsn.selectionStart || txtExprsn.selectionStart == '0') { var startPos = txtExprsn.selectionStart; var endPos = txtExprsn.selectionEnd; txtExprsn.value = txtExprsn.value.substring(0, startPos) + lsbFunction[lsbFunction.selectedIndex] + txtExprsn.value.substring(endPos, txtExprsn.value.length); } else { txtExprsn.value += lsbFunction[lsbFunction.selectedIndex]; } Am calling this function onclick method of the listbox.. Thanks in Advance, kannak.......

              kannak

              P Offline
              P Offline
              Prosanta Kundu online
              wrote on last edited by
              #6

              Hi here is your code <pre> <html xmlns="http://www.w3.org/1999/xhtml" > <head> <title>Selection Test Page</title> <script language="javascript" type="text/javascript"> function insertTextFun() { if (document.selection) { document.getElementById("txtExprsn").focus(); var sel = document.selection.createRange(); var varname = document.getElementById("lsbFunction"); sel.text = varname.options[varname.selectedIndex].text; document.getElementById("txtExprsn").focus(); } else if (window.getSelection()) { var input = document.getElementById("txtExprsn"); var varname = document.getElementById("lsbFunction"); var start = input.selectionStart; var end = input.selectionEnd; var insText = input.value.substring(start, end); input.value = input.value.substr(0, start) + varname.options[varname.selectedIndex].text + input.value.substr(end); input.selectionStart = start; input.selectionEnd = (start + varname.options[varname.selectedIndex].text.length); input.focus();      } else { txtExprsn.value += lsbFunction[lsbFunction.selectedIndex]; } } </script> </head> <body > <select id="lsbFunction" size=5 onclick="insertTextFun()"> <option value="function1">function1</option> <option value="function2">function2</option> <option value="function3">function3</option> <option value="function4">function4</option> <option value="function5">function5</option> </select> <textarea id="txtExprsn" rows="10" cols="40"> This is an example of [bla bla bla] selection. </textarea> </body> </html> </pre> Cheers Prosanta Kundu

              modified on Thursday, January 28, 2010 5:04 AM

              S 1 Reply Last reply
              0
              • P Prosanta Kundu online

                Hi here is your code <pre> <html xmlns="http://www.w3.org/1999/xhtml" > <head> <title>Selection Test Page</title> <script language="javascript" type="text/javascript"> function insertTextFun() { if (document.selection) { document.getElementById("txtExprsn").focus(); var sel = document.selection.createRange(); var varname = document.getElementById("lsbFunction"); sel.text = varname.options[varname.selectedIndex].text; document.getElementById("txtExprsn").focus(); } else if (window.getSelection()) { var input = document.getElementById("txtExprsn"); var varname = document.getElementById("lsbFunction"); var start = input.selectionStart; var end = input.selectionEnd; var insText = input.value.substring(start, end); input.value = input.value.substr(0, start) + varname.options[varname.selectedIndex].text + input.value.substr(end); input.selectionStart = start; input.selectionEnd = (start + varname.options[varname.selectedIndex].text.length); input.focus();      } else { txtExprsn.value += lsbFunction[lsbFunction.selectedIndex]; } } </script> </head> <body > <select id="lsbFunction" size=5 onclick="insertTextFun()"> <option value="function1">function1</option> <option value="function2">function2</option> <option value="function3">function3</option> <option value="function4">function4</option> <option value="function5">function5</option> </select> <textarea id="txtExprsn" rows="10" cols="40"> This is an example of [bla bla bla] selection. </textarea> </body> </html> </pre> Cheers Prosanta Kundu

                modified on Thursday, January 28, 2010 5:04 AM

                S Offline
                S Offline
                sekannak
                wrote on last edited by
                #7

                Hi, Thanks u for your response, i will use this code...... regards, kannak......

                kannak

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups