Web Hosting Talk







View Full Version : Javascript - image selection code


-Edward-
06-15-2006, 09:28 AM
Hi All,

I was wondering if someone would be able to help me with a small peice of javascript? Well i'm assuming it's small but since I don't know javascript I could be wrong.

What I require is if someone clicks a button it inputs some text into a field on a form. The images would pop-up in a window that would display all images. Below each image there would be three buttons each clickable that would force code onto another page's textarea. the information it would force into the form would be an img tag that either aligns the code to the right, left or center. When the button is clicked it would also close the pop-up window.

Is it possible? I don't know how i'd code it so as much help or code snippets would be very helpful. Thanks in advance.

NickDev
06-15-2006, 09:49 AM
Are you looking for help or someone to do it for you? assign an id to your text boxes ect. use var formelem = document.getElementById("id"); to reference your element. You can change the values using formelem.value='bleh'; to tell when a button is clicked you use the onClick event, formelem.onClick = functiontorun

-Edward-
06-15-2006, 10:01 AM
I have a small knowledge of javascript so maybe able to construct the code myself, but my knowledge is very limited.

Would something like this work:

<script type="text/javascript">
function insertcode(insert)

var textarea = document.getElementById("textbox");

var textbox = open + textarea.value.substring(textarea.selectionStart, textarea.selectionEnd) + close;

textarea.focus();



Then on my form:



<input type=submit name=image value="img src=images/imagename.gif" onsubmit="return insert;">



I'm not very good with javascript so my example is probably very wrong.