Jump to content

inserting image


dimitar

Recommended Posts

Hi. I made some script. Its some kind of simple blog. At the form where i put content i gave just title and body textareas. But i want to add some options like inserting images(when klick a litle icon for image pop-up to show and inside the pop-up to insert the url. and that to appear to body form.Or maybe like this:25929648tv3.jpgits not important what code will be inserted, its important that i want to see the system. I think this is not possible with php, but i asked any case. JS is also accepted;D

Link to comment
Share on other sites

You'll need to use Javascript for the interface, not PHP. You can have the image button run a Javascript function that will use the prompt function to get a value from the user like the location of the image, and then you can insert the image tag with their value for the src attribute into the text field.

Link to comment
Share on other sites

I'm not sure if <textarea>s can actually contain anything other than text, but you can try this.HTML:

Image: <input type="text" id="image" /> <input type="button" value="Click here" onclick="addImage()" /><br /><textarea id="output"></textarea>

This goes in the <head> of the document:

function addImage() {im = document.createElement("img");im.src = document.getElementById("image").value;document.getElementById("output").appendChild(im);}

Link to comment
Share on other sites

Textareas can't contain images without some pretty complex JavaScript (I.E. has window.exec() but that is browser-specific), but you could insert image code into the textarea

<script type="text/javascript">function insertimage(target) {src = prompt("Enter Image Location");document.getElementById('target').value += "<img src=\"" + src + "\" />";}</script>

Then the button uses the onclick handler to call the script, and target refers to the id of the textarea.

Link to comment
Share on other sites

What should i change/add to this to work?

<html><head><script type="text/javascript">function insertimage(target) {src = prompt("Enter Image Location");document.getElementById('target').value += "<img src=\"" + src + "\" />";}</script></head><body><form><textarea cols="10" rows="10" id="target"></textarea><input type="submit" name=""></form></body></html>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...