🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: pl.comp.lang.javascript
3 messages
3 total messages Started by mosh Sat, 21 Nov 2009 11:59
Wypełnianie i czyszczenie teaxarea
#49526
Author: mosh
Date: Sat, 21 Nov 2009 11:59
62 lines
2165 bytes
Witam
Od razu zaznaczam, że jestem gorzej niż lama z JS ;)

Chciałbym napisać skrypt w JS, po zdarzeniu onclick
wypełnia mi textarea jakimś tekstem, po kolejnym kliknięciu
kasuje jego zawartość i wypełnia innym tekstem (zastępuje bieżący innym)

naskrobałem takie coś:

JS:

function wypelnij_TA(x) {
	var org = new Array();
		org[6] = 'oryginal txt';
	var tra = new Array();
		tra[6] = 'translated txt';
	
	// ponizsze powinno czyscic TA
	//document.translator.TA_org.value='';
	//document.translator.TA_tra.value='';
	
	
	//wyplenianie TA
	htmlData(org[x], 'TA_org');
	htmlData(tra[x], 'TA_tra');

}


function htmlData(selectValue,targetTextArea)
{

    var txtNode=document.createTextNode(selectValue);
    var textArea=document.getElementById(targetTextArea);

    textArea.appendChild(txtNode);

}

HTML:
<span onclick="wypelnij_TA('6');">wypełnij TA</span>

<form name="translator" id="translator" method="post" action="#">
	<textarea name="TA_org" id="TA_org" disabled="disabled" 
cols="40"></textarea>
	<textarea name="TA_tra" id="TA_tra" cols="40"></textarea>
</form>


wypełnianie TextArea działa, ale każde onclick dodaje kolejny text do 
zawartości.
Więc przed wypełnieniem dodaje:

document.translator.TA_org.value='';

ale wtedy textarea w ogóle się nie wypełnia :/


Jakiś pomysł jak to rozwiązać ?
będę wdzięczny za pomoc :D

pozdro, mosh
Re: Wypełnianie i czyszczenie teaxarea
#49527
Author: fuzjusz
Date: Sun, 22 Nov 2009 11:49
19 lines
1599 bytes
<html>
	<head>
		<script type="text/javascript">

napisy=new Array("jeden txt","222 txt","ttt tekst");
licznik=0;

function napisz(){
	document.getElementById("miejsce").value=napisy[licznik];
	if(++licznik == napisy.length) licznik=0;
}

		</script>
	</head>
	<body>
		<textarea id="miejsce"></textarea>
		<input type="button" value="przycisk" onclick="napisz();" />
	</body>
</html>
Re: Wypełnianie i czyszczenie teaxarea
#49528
Author: mosh
Date: Mon, 23 Nov 2009 17:00
6 lines
1011 bytes
fuzjusz pisze:
> <html>
[...]


trochę inaczej już to rozwiązałem, ale dzięki :D i pozdro
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads