...

View Full Version : How do I get the return value from an alert box ?



jeddi
01-27-2009, 03:00 PM
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 ;)

http://www.devchoice.info/images/alert.jpg

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 ?

rangana
01-27-2009, 03:11 PM
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 (http://www.w3schools.com/JS/js_popup.asp).

jeddi
01-27-2009, 04:09 PM
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 ?


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


And should I write:



<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 :thumbsup:

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 !

rangana
01-27-2009, 04:14 PM
Should be like this:


<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.

jeddi
01-27-2009, 04:41 PM
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:


<img class="imgbtn" src="/picts/in_image.gif" width="21" height="20" alt="Insert Image" title="Insert Image" onClick="wrapText(document.getElementById('ThePromptBox'),'','');">

And the prompt box code:

alert('The URL of the image is: '+imgInp)


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

rangana
01-27-2009, 04:47 PM
You might mean this:


<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,'','');">

jeddi
01-27-2009, 05:10 PM
Well I think its close,

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

Here is the BOLD image.


<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:

http://www.devchoice.info/images/alert02.jpg

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 :confused:

jeddi
01-27-2009, 06:54 PM
OK

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



<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'),''+promptInp,'');">

which does the job :):):D:D



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum