Hi!
Hab folgendes Script, um Inhalte eines Formulars zu formatieren:
Problem: Ich hab mehr als nur EIN Formularfeld (in diesem Fall 'text1'). Wie kann ich dieses Script auf mehrer Felder anwenden? ['text1', 'text2'] funkt nicht.
Sorry, bin absoluter JS-Newbie und bin mir sicher, daß die Lösung supereinfach ist - ich weiss es halt im Moment nur einfach nicht besser... :?
Danke für euern Support.
LG, Citral
Hab folgendes Script, um Inhalte eines Formulars zu formatieren:
Code:
<script type="text/javascript">
<!--
function insert_text(what,info)
{
if (document.selection) // für IE
{
var str = document.selection.createRange().text;
if(str != "")
{
document.form.elements['text1'].focus();
var inb = document.selection.createRange();
inb.text = "<" + what + ">" + str + "</" + what + ">";
return;
}
else
{
// wenn nichts gewählt wurde, mache ein prompt und hängs hinten an
inb = prompt(info,"");
if(inb != "" && inb != null)
{
document.form.elements['text1'].value += " ["+what+"]"+inb+"[/"+what+"] ";
document.form.elements['text1'].focus();
}
}
}
else if (document.getElementById && !document.all) // für Mozilla/Gecko
{
var txtarea = document.form.elements['text1'];
var selLength = txtarea.textLength;
var selStart = txtarea.selectionStart;
var selEnd = txtarea.selectionEnd;
if (selEnd == 1 || selEnd == 2)
selEnd = selLength;
var start = (txtarea.value).substring(0,selStart);
var inb = (txtarea.value).substring(selStart, selEnd)
if(inb != "")
{
var end = (txtarea.value).substring(selEnd, selLength);
txtarea.value = start + '[' + what + ']' + inb + '[/' + what + ']' + end;
return;
}
else
{
// wenn nichts gewählt wurde, mache ein prompt und hängs hinten an
inb = prompt(info,"");
if(inb != "" && inb != null)
{
document.form.elements['text1'].value += " ["+what+"]"+inb+"[/"+what+"] ";
document.form.elements['text1'].focus();
}
}
}
}
// -->
</script>
Problem: Ich hab mehr als nur EIN Formularfeld (in diesem Fall 'text1'). Wie kann ich dieses Script auf mehrer Felder anwenden? ['text1', 'text2'] funkt nicht.
Sorry, bin absoluter JS-Newbie und bin mir sicher, daß die Lösung supereinfach ist - ich weiss es halt im Moment nur einfach nicht besser... :?
Danke für euern Support.
LG, Citral