Как привязать input к textarea?
Здравствуйте, товарищи!:)
У меня форма с несколькими textarea. Есть input который призван выделять весть текст в textarea: <input type="button" value="Select All" onclick="javascript:highlight(0)" onmouseover="window.status='';return true"> Сам скрипт такой: function highlight(x) { document.forms[x].elements[0].focus() document.forms[x].elements[0].select() } Мне нужно привязать input к textarea по id, как например, здесь: <input type="button" value="p" onclick="tag (document.getElementById ('abstract'), '<p>', '</p>')"> где «abstract» — id textarea. Как это сделать, господа? |
Цитата:
|
Цитата:
<!DOCTYPE html> <html> <head> <title>Forms</title> <script type="text/javascript"> function highlight(x){ document.forms[x].elements[0].focus() document.forms[x].elements[0].select() } </script> </head> <body> <form id="editor" name="editor" action="#"> <label>Description</label> <textarea id="description"></textarea> <label>Abstract</label> <textarea id="abstract"></textarea> <input type="button" value="Select All" onclick="javascript:highlight(0)" onmouseover="window.status='';return true" /> </form> </body> </html> При нажатии на input, текст выделяется только в первом textarea, а нужно, чтобы у каждого textarea, был свой input для выделения всего текста. |
Решение влоб
<!DOCTYPE html> <html> <head> <title>Forms</title> <script type="text/javascript"> function highlight(x){ document.forms[0].elements[x].focus() document.forms[0].elements[x].select() } </script> </head> <body> <form id="editor" name="editor" action="#"> <label>Description</label> <textarea id="description"></textarea> <label>Abstract</label> <textarea id="abstract"></textarea><br> <input type="button" value="Select All Description" onclick="javascript:highlight(0)" onmouseover="window.status='';return true" /> <input type="button" value="Select All Abstract" onclick="javascript:highlight(1)" onmouseover="window.status='';return true" /> </form> </body> </html> |
Цитата:
|
Chile,
Потому и влоб - в соответствии с макетом. При более сложной верстке вместо формс.елементс можно применить различные селекторы - по ид, по классу и тп |
Цитата:
|
Цитата:
|
Цитата:
document.getElementById('тут_ИД') |
Chile,
<!DOCTYPE html> <html> <head> <title>Forms</title> <script type="text/javascript"> function highlight(id){ var elem = document.getElementById(id); elem.focus() elem.select() } </script> </head> <body> <form id="editor" name="editor" action="#"> <label>Description</label> <textarea id="description"></textarea> <label>Abstract</label> <textarea id="abstract"></textarea><br> <input type="button" value="Select All Description" onclick="highlight('description')" onmouseover="window.status='';return true" /> <input type="button" value="Select All Abstract" onclick="highlight('abstract')" onmouseover="window.status='';return true" /> </form> </body> </html> |
Часовой пояс GMT +3, время: 04:52. |