Autor Zpráva
Anonymní
Profil *
ahoj all
ako urobit, ked chcem aby sa po kliknuti na obrazok ahoj.jpg ktory je vedla textarea vlozil do textarea name="meno" text "AHOJ" ??? diky
habendorf
Profil
Tohle by mělo fungovat:


<textarea name="meno" id="idecko" value=""></textarea>
<a href="#" onclick="document.getElementById('idecko').value='ahoj'"><IMG SRC="ahoj.jpg"></a>
habendorf
Profil
A takhle to bude ještě lepší, hned to dá focus:


<textarea name="meno" id="idecko" value=""></textarea>
<a href="#" onclick="document.getElementById('idecko').focus(); document.getElementById('idecko').value='ahoj'">
<IMG SRC="ahoj.jpg">
</a>
Anonymní
Profil *
ale mne to potom vymaže text !? a chcel som, aby sa to vkladalo normalne za text
pyty
Profil
<script type="text/javascript">
<!--
function insert(what)
{
if (document.forms['form_name'].elements['textarea_name'].createTextRange )
{
document.forms['form_name'].elements['textarea_name'].focus();
document.selection.createRange().duplicate().text = what;
}
else if ((typeof document.forms['form_name'].elements['textarea_name'].selectionStart) != 'undefined') // for Mozilla
{
var tarea = document.forms['form_name'].elements['textarea_name'];
var selEnd = tarea.selectionEnd;
var txtLen = tarea.value.length;
var txtbefore = tarea.value.substring(0,selEnd);
var txtafter = tarea.value.substring(selEnd, txtLen);
var oldScrollTop = tarea.scrollTop;
tarea.value = txtbefore + what + txtafter;
tarea.selectionStart = txtbefore.length + what.length;
tarea.selectionEnd = txtbefore.length + what.length;
tarea.scrollTop = oldScrollTop;
tarea.focus();
}
else
{
document.forms['form_name'].elements['textarea_name'].value += what;
document.forms['form_name'].elements['textarea_name'].focus();
}
}
//-->
</script>


<form id="form_name" .....>
<textarea id="textarea_name">
</textarea>
</form>
<img src="img/21.gif" alt="" width="12" height="12" onclick="insert('**21');" style="cursor: hand; cursor: pointer" />
habendorf
Profil
Pyty: Zdá se mi to trochu zbytečně složitý.

Anonymní: Myslel jsem, že tím ahoj se bude začínat. Stačí ale dopsat jedno plus:


<textarea name="meno" id="idecko" value=""></textarea>
<a href="#" onclick="document.getElementById('idecko').value+='ahoj'"><IMG SRC="ahoj.jpg"></a>
pyty
Profil
a ked to chces pre viac veci jednoduchsie posluzi funkcia v hlavicke :

<script type="text/javascript">
<!--
function vloz(co)
{ document.getElementById('idecko').value += co; }
//-->
</script>


a obsah:

<textarea id="idecko"></textarea>
<input type="button" value="ahoj" onclick="vloz('Ahoj');">
<input type="button" value="Iny text" onclick="vloz('Iny text');">
<input type="button" value="Uplne iny text" onclick="vloz('Uplne iny text');">
Toto téma je uzamčeno. Odpověď nelze zaslat.

0