Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Senior Coder
    Join Date
    May 2006
    Posts
    1,680
    Thanks
    28
    Thanked 4 Times in 4 Posts

    How do I get the return value from an alert box ?

    Hi,

    I am using BBcodes and want to allow the client to enter
    their image url into an alert box.

    Exactly as it is done in this forum



    Its a picture of this post !

    Anyway - is this using a javascript alert box or a pop up window?
    How do I put the input box into it ?

  • #2
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    Code:
    var imgInp=prompt('Please enter the URL of your image','http://'); // Store the value to imgInp var
    alert('The URL of the image is: '+imgInp);
    It is a prompt box.
    Learn how to javascript at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph

  • #3
    Senior Coder
    Join Date
    May 2006
    Posts
    1,680
    Thanks
    28
    Thanked 4 Times in 4 Posts
    Thanks rangana,

    And can I combine this with my other question (which you also answered) so that the prompt box will appear onChange() ?

    Does this bit go in the <head> in <script> tags ?

    Code:
    var imgInp=prompt('Please enter the URL of your image','http://'); // Store the value to imgInp var
    And should I write:

    Code:
    <select name="x_size" onmouseup(alert('The URL of the image is: '+imgInp)) onChange="wrapText(document.getElementById('TheTextArea'),'','');">  
    <option value = '8' >8 &nbsp;&nbsp;</option>
    <option value = '10' >10 &nbsp;&nbsp;</option>
    etc etc
    Thanks again for helping out

    Actually I want the input to the prompt box to be the text between the tags,
    but I am not sure how to achieve that !
    Last edited by jeddi; 01-27-2009 at 03:11 PM.

  • #4
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    Should be like this:
    Code:
    <select name="x_size" onChange="wrapText(document.getElementById('TheTextArea'),'','');alert('The URL of the image is: '+imgInp)">
    ...not sure what you mean about the "input to the prompt box be the text between the tags".

    Please be a little bit clearer. There are lots of tags...and I"m confused.
    Learn how to javascript at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph

  • #5
    Senior Coder
    Join Date
    May 2006
    Posts
    1,680
    Thanks
    28
    Thanked 4 Times in 4 Posts
    Yes, I am not surprised you are confused !
    I have mixed up 2 seperate questions !!

    The prompt box is for the user to enter an image url
    so I want to capture the url with the alert and then
    insert the entered url between the (img) (/img) tags.

    I've used round brackets in this post so it doesn't mess
    up the bbcode in this forum !

    So here is the code I have:
    Code:
    <img class="imgbtn" src="/picts/in_image.gif" width="21" height="20" alt="Insert Image" title="Insert Image" onClick="wrapText(document.getElementById('ThePromptBox'),'[img]','[/img]');">
    And the prompt box code:
    Code:
    alert('The URL of the image is: '+imgInp)

    I guess that I need to change "getElementById('ThePromptBox')" to something else ?

  • #6
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    You might mean this:
    Code:
    <img class="imgbtn" src="/picts/in_image.gif" width="21" height="20" alt="Insert Image" title="Insert Image" onClick="promptInp =prompt('Please enter the URL of your image','http://');wrapText(promptInp,'[img]','[/img]');">
    Learn how to javascript at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph

  • #7
    Senior Coder
    Join Date
    May 2006
    Posts
    1,680
    Thanks
    28
    Thanked 4 Times in 4 Posts
    Well I think its close,

    I realise now, that I still need to reference the textarea.

    Here is the BOLD image.

    Code:
    <img class="imgbtn" src="/picts/bold.gif" width="21" height="20" alt="Bold" title="Bold" onClick="wrapText(document.getElementById('TheTextArea'),'','');">
    I think that the wrapText function may not be needed.
    The wrap text function is looking to see what text has been highlighted

    In the case of entering the image url, it is just a case of inserting the two tags with the user supplied url into the textarea at the cursor position.
    so that we end up with this:



    So the getElementById('TheTextArea') reference needs to go back in and the
    wrapText function can come out.

    - but I don't know how to insert the tags and input at
    the cursor position in the textarea

  • #8
    Senior Coder
    Join Date
    May 2006
    Posts
    1,680
    Thanks
    28
    Thanked 4 Times in 4 Posts
    OK

    I have got it - after quite a few trys,
    I have ended up with:

    Code:
    <img class="imgbtn" src="/picts/in_image.gif" width="21" height="20" alt="Insert Image" title="Insert Image" onClick="promptInp =prompt('Please enter the URL of your image','http://');wrapText(document.getElementById('TheTextArea'),'[img]'+promptInp,'[/img]');">
    which does the job


  •  

    Posting Permissions

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