-3

How to create a html with Many buttons but result should be displayed in one Textbox and the text should be pre-defined i.e if Button1 is pressed it should have a predefined text should be displayed in the textbox...

And moroever if you can copy that same text in clipboard via a script....

Many Thanks in Advance

CrashOverride
  • 338
  • 3
  • 10
  • 22

1 Answers1

0

Check out the following, http://jsfiddle.net/eHzwF/

<html>
    <head>
        <script>
        function clickedIt(buttonValue){
            document.getElementById('txt').value = buttonValue;
        }
        </script>
    </head>
    <body>
        <input type='text' id='txt' value=''/>
        <input type='button' value='Button1' onclick='clickedIt("Button1")'/>
        <input type='button' value='Button2' onclick='clickedIt("Button2")'/>
        <input type='button' value='Button3' onclick='clickedIt("Button3")'/>        
    </body>
</html>​

is this what you are trying to do?

I29
  • 686
  • 4
  • 9
  • That is exactly what i've been looking for thanks a ton – CrashOverride Dec 12 '12 at 16:51
  • MY ORIGINAL CODE Fill Text Area – CrashOverride Dec 12 '12 at 16:51
  • However can we have it copied to clipboard at the same time by any chance – CrashOverride Dec 12 '12 at 16:52
  • Check this out: http://stackoverflow.com/questions/7713182/copy-to-clipboard-for-all-browsers-using-javascript – I29 Dec 13 '12 at 05:51
  • and this, http://www.itjungles.com/javascript/javascript-easy-cross-browser-copy-to-clipboard-solution – I29 Dec 13 '12 at 05:52
  • It works perfectly for me "i can't thank you enogh" – CrashOverride Dec 13 '12 at 10:05
  • Can you check this fiddle for me please http://jsfiddle.net/UDCB8/ Your querry works perfectly all i want to do with is "I WANT TO CLICK ONE BUTTON AND A PREDEFINED TEXT SHOULD BE DISPLAYED AND ALSO COPIED TO THE CLIPBOARD" FOR.EG IF WE PRESS BUTTON1 PREDEFINED TEXT LIKE "LOREM IPSUM" SHOULD BE DISPLAYED IN TEXTBOX AND COPIED TO THE CLIPBOARD ANY IDEA HOW TO ACHIEVE THIS ?I AM OK IF IT ONLY WORKS IN IE7(preference) OR ANY IE.... – CrashOverride Dec 13 '12 at 10:10
  • If it's ok that it works in IE only then this is way less code than that ^ http://jsfiddle.net/siyakunde/UDCB8/2/ This only works with IE 4 and above – I29 Dec 13 '12 at 12:50
  • You my friend have exceeded my expections, this works flawlessly.I owe you one. – CrashOverride Dec 13 '12 at 16:21
  • this is the last one i should ask you ,,,your script is great it just that it copies the button value instead can we do it to copy the textarea value(predefined text) that we are displaying in it.It just copies the buttonValue like Button1 but instead can we do it to text area. – CrashOverride Dec 14 '12 at 07:18
  • done! check this out. http://jsfiddle.net/siyakunde/UDCB8/3/ – I29 Dec 14 '12 at 09:08
  • Now that's what i have say – CrashOverride Dec 14 '12 at 14:48