SitePoint Sponsor

User Tag List

Results 1 to 11 of 11

Hybrid View

  1. #1
    Original Gangster silver trophy Thing's Avatar
    Join Date
    Oct 2000
    Location
    Philadelphia, PA
    Posts
    4,708
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    add hyperlink popup

    I want to do exactly what SitePoint does when you click on the "insert link" icon. Basically popup a little window asking for the URL and the text to be linked. Then when they click add it will put those values into the textarea on the form. I want to make sure that whatever the user has already wrote into the form is not replaced by the link, but the link is appended to the end.

    Any help would be great! Thanks

  2. #2
    SitePoint Enthusiast kgish's Avatar
    Join Date
    Dec 2001
    Location
    Gouda, The Netherlands
    Posts
    64
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The most straight-forward way to do this is by using the standard prompt() function.

    Code:
    var url = prompt('Enter the URL: ' , 'http://' );
    var txt = prompt('Enter the text: ', '');
    Kiffin
    Your average future-famous kind of guy...

  3. #3
    Original Gangster silver trophy Thing's Avatar
    Join Date
    Oct 2000
    Location
    Philadelphia, PA
    Posts
    4,708
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    how do I get that information to post into the textarea on my form on the original page the popup button is on?

  4. #4
    Original Gangster silver trophy Thing's Avatar
    Join Date
    Oct 2000
    Location
    Philadelphia, PA
    Posts
    4,708
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I've done a lot of searching, but have yet to come across this. Any takers?

  5. #5
    SitePoint Wizard silver trophy rushiku's Avatar
    Join Date
    Dec 2003
    Location
    A van down by the river
    Posts
    2,056
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)

  6. #6
    Original Gangster silver trophy Thing's Avatar
    Join Date
    Oct 2000
    Location
    Philadelphia, PA
    Posts
    4,708
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    That code is close, however it will OVERWRITE the data already in the textarea. It needs to append itself to the end of whatever the user types.

  7. #7
    SitePoint Wizard silver trophy rushiku's Avatar
    Join Date
    Dec 2003
    Location
    A van down by the river
    Posts
    2,056
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    textarea.value += prompt
    or
    textarea.value = textarea.value + promt

  8. #8
    Original Gangster silver trophy Thing's Avatar
    Join Date
    Oct 2000
    Location
    Philadelphia, PA
    Posts
    4,708
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Here's what I have. Basically instead of a javascript popup it is using javascript to popup a website:

    Code:
    <%
    If request.querystring("action") = "url" then
    %>
    <table align="center">
    <tr>
    <td width=30%>URL</td>
    <td><input type="text" name="url" value="http://" size="70"></td>
    </tr><tr>
    <td width=30%>Name</td><td><input type="text" name="name"></td></tr>
    <tr><td colspan="2"><input type="submit" name="addlink" value="Add Link">
    </table>
    <%
    response.end
    End if
    %>
     <center>
     <a href="test.asp?action=url" ONCLICK="popup(this.href);return false" TARGET="win" style="color:#000000">Add Link</a>
     </center>
     <SCRIPT>
     function popup(p)
     {
     var newWin;
     params="width=500, height=150"
     w=window.open(p,"win",params)
     }
     </SCRIPT>
     <form name="aaa">
     <center>
     <textarea name="message"></textarea>
     </center>
     </form>
    So how would I incorporate that to enter into the textarea?? I appreciate your help by the way

  9. #9
    SitePoint Wizard silver trophy rushiku's Avatar
    Join Date
    Dec 2003
    Location
    A van down by the river
    Posts
    2,056
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    I was under the impression you were using a prompt...
    browser windows don't 'naturally' return values, like the dialogs (like prompt) do, so you could do something along these lines:

    not sure how cross-browser this is, it works in IE6 and firebird.7

    Code:
    file:foo.html
    
    <html>
    <head></head>
    <body>
     <input type='text' id='txt'></input>
     <button onclick='go();'>click</button>
    </body>
    <script>
    function go() {
      window.open("bar.html");
    }
    </script>
    </html>
    
    file: bar.html
    <html>
    <head>
    <script>
    function go() {
    window.opener.document.getElementById('txt').value +=
      document.getElementById('ta').value;
    }
    </script>
    </head>
    <body>
    <textarea id='ta'></textarea>
    <button onclick='go();window.close();'>close</button>
    </body>
    </html>
    basically, the go code in bar.html gets the txt element from the page that opened it (foo.html, in this case) and appends the value of the ta element to its value.

    The code should be improved to determine which element on the calling page to populate, and the element on bar.html to get the data from, for that matter, via some args passed in the window.open() call.
    check out the window.open method

  10. #10
    Original Gangster silver trophy Thing's Avatar
    Join Date
    Oct 2000
    Location
    Philadelphia, PA
    Posts
    4,708
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I ended up taking an easier route. Now when they click the URL button it places the actual HTML code for a link into the textbox:

    Code:
    <html>
    <head>
    <title></title>
    <script language="javascript" type="text/javascript">
    function insertCode(sInput) {
    InputForm.Body.value = InputForm.Body.value + sInput;
    }
    </script>
    </head>
    <body><form name="InputForm">
    <input type="button" value="BOLD" id="btnBold" onClick="insertCode('<b></b>')">
    <input type="button" value="Underline" id="btnUnderline" onClick="insertCode('<u></u>')">
    <input type="button" value="Link" id="btnLink" onClick="insertCode('<a href=\'http://www.domain.com\'> Link Text</a>')">
    <hr />
    <textarea name="Body"></textarea>
    </form>
    </body>
    </html>

  11. #11
    Original Gangster silver trophy Thing's Avatar
    Join Date
    Oct 2000
    Location
    Philadelphia, PA
    Posts
    4,708
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Ok I decided to try it again. Here's what I have:

    Code:
    <script>
    function doImage()
    {
       var url = prompt('Enter name for link', '');
       if(url != null) editor.document.execCommand('createlink', true, url );
    }
    </script>
    <body onLoad="editor.document.designMode='On'">
    	 <button onClick="doImage()">URL</button><br>
    	 <textarea name="editor"></textarea>
    </body>
    </html>
    Now it creates the link, however it places it at the top of the page. How can I get the link to append to the textarea? Thanks!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •