Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
add text to form when image clicked
Old 09-25-2005, 09:36 AM add text to form when image clicked
phil-b's Avatar
Average Talker

Posts: 24
Location: London
Trades: 0
I need a little piece of javascript that when a picture is clicked the name of the picture will be added to the text area (rather similar to the buttons on forums) wrapped in UBB as follows:
Code:
[IMG]picturename.jpg[/IMG]
It is all database driven (programmed in ASP) so i may need to use hidden fields

thanks in advance for any help

P
phil-b is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 09-25-2005, 11:50 AM
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,519
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Code:
<img id="pic_id" onclick="document.forms['thisform'].picname.value = this.src" src="blah.jpg" alt="" />
<form name="thisform" id="thisform" action="" method="get">
<input type="text" name="picname" id="picname"/>
</form>
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 09-25-2005, 08:03 PM
phil-b's Avatar
Average Talker

Posts: 24
Location: London
Trades: 0
Thanks for the help thats pretty much what i need but i could do with it being slightly different.

- instead of entering th whole image name location is there any chance it could just use the name
eg picture.jpg instead of http://www.whatever.com/whatever/picture.jpg

- could it also wrap the name in UBBC tags like [IMG]picture.jpg[/IMG]

- Is it possible for it to add to the text instead of replacing everything that is already there?

- Also (not critical but would be nice) each image that will be clicked is named th_picture.jpg as they are thumbs but the ones that will be inserted are just called picture.jpg, if theres any chance the th_ could be clipped off the front too that would be marvelous (i'm really clutching at straws with that one!)

Sorry if im asking a lot, i dont mean to be ungrateful!

Thanks again for the help
P

Last edited by phil-b; 09-25-2005 at 08:12 PM..
phil-b is offline
Reply With Quote
View Public Profile
 
Old 09-25-2005, 09:16 PM
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,519
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
It has to be converted to a function to accomplish that. Bit complex for inline code.

Code:
<script type="text/javascript">
function addPicName(pic_name) {
pic_name = pic_name.replace('th_','');
document.forms['thisform'].picname.value = document.forms['thisform'].picname.value + ' [img]' + pic_name.substr(pic_name.lastIndexOf('/')+1) '[/img] ';
}
</script>
Code:
<img id="pic_id" onclick="addPicName(this.src)" src="imagename.jpg" alt="" />

<form name="thisform" id="thisform" action="" method="get">
<input type="text" name="picname" id="picname" size="50" value="Picture Name is" >
</form>
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 09-26-2005, 10:08 AM
phil-b's Avatar
Average Talker

Posts: 24
Location: London
Trades: 0
Thanks again it looks like that will do Perfectly but it doesnt seem to be working for me (have checked in IE and FF)

I did have to edit a few bits such as the name of the form and text field but cant see why it isnt working.

Code:
<script type="text/javascript">
function addPicName(pic_name) {
pic_name = pic_name.replace('th_','');
document.forms['form'].page_content.value = document.forms['form'].page_content.value + ' [img]' + pic_name.substr(pic_name.lastIndexOf('/')+1) '[/img] ';
}
</script>
Code:
<img id="pic_5" onclick="addPicName(this.src)" src="../images/photo/th_Tie.jpg" height="80" />
Code:
<form name="form" id="form" action="page_edit.asp?Page_ID=2" method="post">
Code:
<textarea name="page_content" id="page_content" cols="55" rows="20" class="input">content goes here</textarea>
Can you see what i've done wrong?

P

Last edited by phil-b; 09-26-2005 at 10:40 AM..
phil-b is offline
Reply With Quote
View Public Profile
 
Old 09-29-2005, 05:56 AM
phil-b's Avatar
Average Talker

Posts: 24
Location: London
Trades: 0
Got it! There was a + missing

Thanks again for the help
phil-b is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to add text to form when image clicked
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.23410 seconds with 12 queries