dear coders,
the code below is just a test script, my code is processed by a mysql while loop.
That's why the form id and function vars are not unique.
I'm trying to solve the getElementById problem...
Only the first textarea is working properly!
Is there a way to use something like getElementsBy selected textarea?
HTML Code:<html> <head> <script type="text/javascript"> function CodeBold(tekstveld_naam){ // code for IE var textarea = document.getElementById(tekstveld_naam); if (document.selection){ textarea.focus(); var sel = document.selection.createRange(); if (sel.text != ''){ sel.text = '<b>' + sel.text + '</b>'; } } // code for Mozilla var textarea = document.getElementById(tekstveld_naam); var len = textarea.value.length; var start = textarea.selectionStart; var end = textarea.selectionEnd; var sel = textarea.value.substring(start, end); var replace = '<b>' + sel + '</b>'; if (sel != ''){ textarea.value = textarea.value.substring(0,start) + replace + textarea.value.substring(end,len); } } function CodeH1(tekstveld_naam){ // code for IE var textarea = document.getElementById(tekstveld_naam); if (document.selection){ textarea.focus(); var sel = document.selection.createRange(); if (sel.text != ''){ sel.text = '<h1>' + sel.text + '</h1>'; } } // code for Mozilla var textarea = document.getElementById(tekstveld_naam); var len = textarea.value.length; var start = textarea.selectionStart; var end = textarea.selectionEnd; var sel = textarea.value.substring(start, end); var replace = '<h1>' + sel + '</h1>'; if (sel != ''){ textarea.value = textarea.value.substring(0,start) + replace + textarea.value.substring(end,len); } } </script> </head> <body> <form id="form1" name="form1" method="post" action=""> <div> <a href="#" onClick="CodeBold('textarea');return false;"><img src="_images/bold.jpg"></a> <a href="#" onClick="CodeH1('textarea');return false;"><img src="_images/h1.jpg"></a> </div> <br /> <textarea name="textarea" id="textarea" cols="45" rows="5">this is the text in the textarea</textarea> </form> <form id="form1" name="form1" method="post" action=""> <div> <a href="#" onClick="CodeBold('textarea');return false;"><img src="_images/bold.jpg"></a> <a href="#" onClick="CodeH1('textarea');return false;"><img src="_images/h1.jpg"></a> </div> <br /> <textarea name="textarea" id="textarea" cols="45" rows="5">this is the text in the textarea</textarea> </form> </body> </html>



Reply With Quote



Bookmarks