Jump to content


JavaScript: Prompt User and Insert to textarea


2 replies to this topic

#1 BigDog

    Young Padawan

  • Members
  • Pip
  • 277 posts
  • Gender:Male
  • Location:Orange County, California
  • Interests:Running, building computers, PC games and BMX and programming.

Posted 15 March 2007 - 10:49 PM

I have created a very small forum system and was going to add a BBCode system in it. I have created the bbcode system and it works fine. If i do the BOLD and all, it will work.

I want to create a button for IMG URL so when you click it, a prompt comes up and asks, whats the url for the image.

I got that far, but now my problem is how to get it into my textarea!

http://bigdog.csscob...forum/thread/2/

Scroll down on that page and you will see the button and the textarea.

my code so far is

function imageprompt()
{
	var imageurl=prompt("Enter Image URL","http://");
	if (imageurl!=null && imageurl!="")
	{
	   document.getElementByName("post").value="[img]" + imageurl + "[/img]";	
	 }
}

That doesn't work for some reason. Anyone wish to help will be great.

#2 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 17 March 2007 - 12:12 AM

Firefox said:

Error: document.getElementByName is not a function
Source File: http://bigdog.csscob...orum/scripts.js
Line: 11
Add an id attribute and change getElementByName to getElementById, or use some fancier DOM
function imageprompt()
{
	var imageurl=prompt("Enter Image URL","http://");
	if (imageurl!=null && imageurl!="")
	{
	   document.quickreply.post.value = imageurl;
	 }
}
I can't say for sure how well that will work as my DOM is a bit rusty, but it gets the point across.

Edited by rc69, 17 March 2007 - 12:12 AM.


#3 BigDog

    Young Padawan

  • Members
  • Pip
  • 277 posts
  • Gender:Male
  • Location:Orange County, California
  • Interests:Running, building computers, PC games and BMX and programming.

Posted 17 March 2007 - 01:44 AM

Thats. that worked great.

For future references for people searching, i used his code and if you want it to show whats in the textarea + the prompt, add a + infront of the =.

	   document.quickreply.post.value += imageurl;

Thanks again.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users