Select image with ExecCommand('insertimage') and write path to textbox

Last post 05-20-2008, 1:04 PM by Adam. 5 replies.
Sort Posts: Previous Next
  •  05-19-2008, 4:14 PM 40533

    Select image with ExecCommand('insertimage') and write path to textbox

    Does anyone know how to use the editor1.ExecCommand('insertimage'); to upload and select an image and have the Insert button cause a textbox to be filled with a path to the image file?
     
    Here is the javascript I have tried but doesn't write path back to imageFld textbox:
         function callInsertIMG() 
        { 
       var editor2 = document.getElementById('<%=editor2.ClientID%>');
                editor2.FocusDocument(); 
                var editdoc = editor2.GetDocument(); 
                editor2.ExecCommand('new');
                editor2.ExecCommand('insertimage');
                InputIMG();
                document.getElementById("ctl00_ContentPlaceHolder1_imageFld").focus();
        }   
       
        function InputIMG()
        {
      var editor2 = document.getElementById('<%=editor2.ClientID%>');
            var editdoc = editor2.GetDocument(); 
            var links = editdoc.getElementsByTagName("a");      
            if(links.length>0&&links[links.length-1].href!="") 
      { document.getElementById("ctl00_ContentPlaceHolder1_imageFld").value = links[links.length-1].href;      
      } 
      else
      {
       setTimeout(InputIMG,500);
      }          
        }
    Thanks for any help
  •  05-19-2008, 4:38 PM 40535 in reply to 40533

    Re: Select image with ExecCommand('insertimage') and write path to textbox

    mlc962,

    Please check the following example:

    How to use CuteEditor as an image selector?
    How to use CuteEditor as an image selector?( Demo1 |  Demo2 )
    This example


    The source code of this example can be found in the download package.
     
    <Script Language="javascript">
        function callInsertImage() 
        { 
       var editor2 = document.getElementById('<%=editor2.ClientID%>');
                editor2.FocusDocument(); 
                var editdoc = editor2.GetDocument(); 
                editor2.ExecCommand('new');
                editor2.ExecCommand('ImageGalleryByBrowsing');
                InputURL();
        }   
       
        function InputURL()
        {
      var editor2 = document.getElementById('<%=editor2.ClientID%>');
            var editdoc = editor2.GetDocument(); 
            var imgs = editdoc.images;
            if(imgs.length>0) 
            { document.getElementById("imageFld").value = imgs[imgs.length-1].src;
                editor2.ExecCommand('new');
                document.getElementById("imageFld").focus();
            } 
            else
            {
       setTimeout(InputURL,500);
            } 
        }      
    </script>
     

    asp.net Chat http://cutesoft.net/ASP.NET+Chat/default.aspx
    Web Messenger: http://cutesoft.net/Web-Messenger/default.aspx
    asp.net wysiwyg editor: http://cutesoft.net/ASP.NET+WYSIWYG+Editor/default.aspx
    asp wysiwyg html editor: http://cutesoft.net/ASP
    asp.net Image Gallery: http://cutesoft.net/ASP.NET+Image+Gallery/default.aspx
    Live Support: http://cutesoft.net/live-support/default.aspx

  •  05-19-2008, 6:42 PM 40538 in reply to 40535

    Re: Select image with ExecCommand('insertimage') and write path to textbox

    I was looking for a way to upload and set elements such as alt text and capture the path of the uploaded file at the same time.
    The 'ImageGalleryByBrowsing' doesn't let you edit size or enter alt text.  It is just an image selector of files.  Or is that not correct?
    Thanks.
  •  05-19-2008, 10:01 PM 40540 in reply to 40538

    Re: Select image with ExecCommand('insertimage') and write path to textbox

    Please change:          

     
            editor2.ExecCommand('ImageGalleryByBrowsing');

    to:

           editor2.ExecCommand('InsertImage');


    asp.net Chat http://cutesoft.net/ASP.NET+Chat/default.aspx
    Web Messenger: http://cutesoft.net/Web-Messenger/default.aspx
    asp.net wysiwyg editor: http://cutesoft.net/ASP.NET+WYSIWYG+Editor/default.aspx
    asp wysiwyg html editor: http://cutesoft.net/ASP
    asp.net Image Gallery: http://cutesoft.net/ASP.NET+Image+Gallery/default.aspx
    Live Support: http://cutesoft.net/live-support/default.aspx

  •  05-20-2008, 11:26 AM 40578 in reply to 40540

    Re: Select image with ExecCommand('insertimage') and write path to textbox

    I'm using master pages on the site and have to use getElementById("ctl00_ContentPlaceHolder1_imageFld")
    Okay this works:
      function callInsertIMG() 
        { 
       var editor2 = document.getElementById('<%=editor2.ClientID%>');
                editor2.FocusDocument(); 
                var editdoc = editor2.GetDocument(); 
                editor2.ExecCommand('new');
                editor2.ExecCommand('InsertImage');
                InputIMG();
                document.getElementById("ctl00_ContentPlaceHolder1_imageFld").focus();
        }   
       
        function InputIMG()
        {
      var editor1 = document.getElementById('<%=Editor2.ClientID%>');
            var editdoc = editor1.GetDocument(); 
            var imgs = editdoc.images;
            if(imgs.length>0) 
            { document.getElementById("ctl00_ContentPlaceHolder1_imageFld").value = imgs[imgs.length-1].src;
       document.getElementById("ctl00_ContentPlaceHolder1_imageFld").focus();
            } 
            else
            {
       setTimeout(InputIMG,500);
            } 
        } 
     
    I'm considering other alternatives to storing and referencing the images and documents for content management.
    I have an sqlexpress data store.  Thought of storing the path to magazine cover image, path to pdf, title of the magazine, short description of main article, etc.
    Wanted to control the size of the image uploaded.
    Need the alt tag filled in for accessibility compliance.
    Does the above script allow the capture of the alt tag that I could send to a textbox value?
    Thanks.
  •  05-20-2008, 1:04 PM 40582 in reply to 40578

    Re: Select image with ExecCommand('insertimage') and write path to textbox

    >>Wanted to control the size of the image uploaded.
     
    Please check the following article:
     
    How to Limit the Size of The Media Files being Uploaded:
     
     
    >>Need the alt tag filled in for accessibility compliance.
     
    var image = imgs[imgs.length-1];
     
    alert("src: "+image.src);
    alert("alt: "+image.alt);
     

     

    asp.net Chat http://cutesoft.net/ASP.NET+Chat/default.aspx
    Web Messenger: http://cutesoft.net/Web-Messenger/default.aspx
    asp.net wysiwyg editor: http://cutesoft.net/ASP.NET+WYSIWYG+Editor/default.aspx
    asp wysiwyg html editor: http://cutesoft.net/ASP
    asp.net Image Gallery: http://cutesoft.net/ASP.NET+Image+Gallery/default.aspx
    Live Support: http://cutesoft.net/live-support/default.aspx

View as RSS news feed in XML