I was wondering how to make onClick copy the contents of an object, such as a div like so:
This would be for use in somthing like List page, where each line is its own <div> </div>.Code:<div> "Skill" 5 </div>
Thanks in advance
Printable View
I was wondering how to make onClick copy the contents of an object, such as a div like so:
This would be for use in somthing like List page, where each line is its own <div> </div>.Code:<div> "Skill" 5 </div>
Thanks in advance
Well what you do then is give each div an ID, and then use the nifty feature in JS getelementbyID, it's up here on w3schools.. JavaScript onclick Event
you will need to look at that code, and then modify how your pages are printed out, because you can only use an ID unique to each div. After labelling each div you can then create a JS function and then give each div an onClick event, or whatver you are going to do to copy it. Sorry if this didn't explain anything I'm in a rush.
Its ok :) i understand what your saying, at the moment i have the divs being generated one line at a time using a foreach, then stripping slashes ( because the skills in the list need to be in the format: "Skill name" 5 for the devs to copy it correctly. )
During the foreach i use a $count and the id is done like so:
This way each div has a uniqe ID ( i had to do it like that to get the onmouseover effect to work on each div in a way i could have the javascript in a seperate function in a file instead of having all the stuff it dose onmouseover and onmouseout in the div itself ).Code:echo "<div id='list$count' class='blah'> $parse </div>";
Also, the onClick in that page cant do it the way i need it to work. The list will be over 122 lines long so a copy button wont be efficient, it would be faster for the devs to just highlight ->rightclick -> copy. That one also copys it into a different field.
What i need it to do is when you click the line itself ( each line is a div with a uniqe id ), i want it to copy whats in the div.
At the moment the div looks like such ( when generated in HTML after viewing the page with the list ):
Thats the HTML for the div ( view source ), and they are displayed going down the page:Code:<div class='list' id='list4' onmouseover="listMouseOver('list4')" onmouseout="listMouseOut('list4')">"Skill Name" 5</div>
Where ( as said above ), each "Skill name x" 5 is a new line, with a new div with a uniqe ID...Code:"Skill name" 5
"Skill name 2" 5
"Skill name 3" 5
etc
What i need is that when you click on the line ( like above, say you click on "Skill name" 5 ) it copys that line into the clipboard for pasting some where else.
Sorry if that was a bit jumbled.. :/ lol, not thinking strait atm.
Im not a javascript expert so im not 100% sure how i could mod what they have on the site to work like the above mentioned.
edit: Sorry, forgot to say thanks for the reply :) i had to run and go do something before i could type it.
I'm sorry, but this is as far as I can help you with, I do not know enough JS to help you copy the contents from the div into clipboard, as there are probably different ways for FF and IE, and I don't know either, but someone else might.. also if you want to do it when you click, you shouldn't be using onMouseOver or onMouseOut
Do they not interact well or somthing? Im still learning javascript so i dont know mutch at all... Still reading up on it and studying code to learn it.
I have the onMouseOver there and onmouseout so that he knows what line hes on easily.
Edit: I should prob mention that the onMouseOver and onMouseOut dose do somthing, just not on the list i provided. I recoded that list into a website im currently developing thats on my local webserver. They are designed to make it easier to see the line he is on when copying them.
And its np, i dont know that much java. I know some one who dose know how to do it prob but hes not on atm, wont be for like another 8 hours if that.
i knew a way before... but firefox doesn't allow it anymore... cause before u can copy stuff the clipboard using exeCommand('copy') .. u have to create a text range... but some browsers dont allow it by default anymore...
Ah... Damn, oh well. They will just have to do it the old way then :o, thanks.
JavaScript: Copy to clipboard
i used the script in there and it worked on .. FF