Need help with javascript popup?

Discussion in 'JavaScript' started by tobydawson13, Jul 7, 2010.

  1. #1
    Hi there could somebody help me out with this bit of javascript?

    <a href="javascript:;" onclick="document.forms[0].a_answer.value=document.forms[0].a_answer.value+'[link=PUT LINK HERE][/link]'">
    Link Here
    </a>
    
    <form id="form1" name="form1" method="post">
    <textarea name="a_answer" cols="50" rows="5" id="a_answer"></textarea>
    </form>
    Code (markup):
    I have this form and when I click the link the text [link=PUT LINK HERE][/link] is entered into the textbox. Does anybody have any ideas how I could edit my current code so that when the link is clicked the user gets a little popup asking "Please enter the URL of your link:" (like here on DP) and the url that the user types in replaces the words "PUT LINK HERE"?.

    Thanks :)
     
    tobydawson13, Jul 7, 2010 IP
  2. Rainulf

    Rainulf Active Member

    Messages:
    373
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    85
    #2
    You mean something like this?
    <script type="text/javascript">
    function populate( ) {
       var value = prompt("Please enter the URL of your link:", "")
       document.forms[0].a_answer.value = "[link=" + value + "][/link]";
    }
    </script>
    
    <a href="#" onclick="populate( );">
    Link Here
    </a>
    
    <form id="form1" name="form1" method="post">
    <textarea name="a_answer" cols="50" rows="5" id="a_answer"></textarea>
    </form>
    Code (markup):
     
    Rainulf, Jul 7, 2010 IP
    tobydawson13 likes this.
  3. tobydawson13

    tobydawson13 Active Member

    Messages:
    645
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    60
    #3
    Cheers :D
    That works perfectly, thanks :)
     
    tobydawson13, Jul 7, 2010 IP