« 1 2 »
Autor Zpráva
shakal
Profil *
potřebuji vložení smajlíku do formuláře.
Včera jsem tu řešil, jak udělat textové smajlíky za grafické. To už funguje jak má.
Ted ale potřebuji toto:

Mám formulář a smajlíky. Jak udělám, když kliknu na smajlíka aby se ve formuláři ukázalo ":-)"
MCKAY
Profil
Párkrát se to tu již řešilo, ale tedy dejme tomu. Mám tu jeden starší skript z diskuse, mírně přepsaný:
function insertsm(tag, parovy, text, prependText, appendText)
{
	//inicializace proměných
	var textarea = document.forms["clanek"].elements["text"];

	var startTag = tag;
	var endTag = '';

	if (typeof text == 'undefined') {
		var tagText = getTextareaSelectionsm();
	} else {
		var tagText = text;
	}
	
	if (typeof parovy == 'undefined') {
		var parovy = true;
	}

	if (typeof prependText == 'undefined') {
		var prependText = '';
	}
	
	if (typeof appendText == 'undefined') {
		var appendText = '';
	}
	
	
	//přepsání výchozích hodnot pro specifické tagy
	if (tag == 'url') {
		if (tagText == '') {
			tagText = 'Odkaz';
		}
		var regexp = new RegExp("^((http|https|ftp)\\://)([a-zA-Z0-9\\.\\-]+(\\:[a-zA-Z0-9\\.&%\\$\\-]+)*@)?((25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])|([a-zA-Z0-9\\-]+\\.)*[a-zA-Z0-9\\-]+\\.[a-zA-Z]{2,4})(\\:[0-9]+)?(/[^/][a-zA-Z0-9\\.\\,\\?\\'\\\\/\\+&%\\$#\\=~_\\-@]*)*$");
		var regexp2 = new RegExp("^([a-zA-Z0-9\\.\\-]+(\\:[a-zA-Z0-9\\.&%\\$\\-]+)*@)?((25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])|www\\.([a-zA-Z0-9\\-]+\\.)*[a-zA-Z0-9\\-]+\\.[a-zA-Z]{2,4})(\\:[0-9]+)?(/[^/][a-zA-Z0-9\\.\\,\\?\\'\\\\/\\+&%\\$#\\=~_\\-@]*)*$");
		
		if (regexp.test(tagText)) {
			startTag = '[url=' + tagText + ']';
		} else if (regexp2.test(tagText)) {
			startTag = '[url=http://' + tagText + ']';
		} else {
			startTag = '[url=http://example.com]';
			selectionStart = prependText.length + 5;
			selectionEnd = prependText.length + 23;
		}
	}
		
	//vytvoření textu pro vložení
	if (!parovy) {
		endTag = '';
	}
		
	var text2insert = prependText + startTag + tagText + endTag + appendText;
	
	//vložení:
	textarea.focus();
	
	if (typeof textarea.selectionStart != 'undefined') {
		var start = textarea.selectionStart;
		var end = textarea.selectionEnd;
		
		textarea.value = textarea.value.substr(0, start) + text2insert + textarea.value.substr(end);
		
		//nastaveni kurzoru na spravné misto / vybrani pozadovaneho textu
		if (typeof selectionStart != 'undefined' && typeof selectionEnd != 'undefined') {
			textarea.selectionStart = start + selectionStart;
			textarea.selectionEnd = start + selectionEnd;
		} else {
			if (tagText == '') {
				//skoceni mezi tagy
				textarea.selectionStart = start + prependText.length + startTag.length;
				textarea.selectionEnd = start + prependText.length + startTag.length;
			} else {
				//skoceni za posledni tag
				textarea.selectionStart = start + text2insert.length;
				textarea.selectionEnd = start + text2insert.length;
			}
		}
	}
	else if (typeof document.selection != 'undefined') {
		var range = document.selection.createRange();
		range.text = text2insert;
		
		//nastaveni kurzoru na spravné misto / vybrani pozadovaneho textu
		if (typeof selectionStart != 'undefined' && typeof selectionEnd != 'undefined') {
			range.moveStart('character', -text2insert.length + selectionStart);
			range.moveEnd('character', -text2insert.length + selectionEnd);
		} else {
			if (tagText == '') {
				//skoceni mezi tagy
				range.move('character', -(endTag.length + appendText.length));
			} else {
				//skoceni za posledni tag
				//protoze prohlizec v tomto pripade skoci za posledni tag automaticky, neni treba nic posouvat	
			}
		}
		range.select();
	}

	//unset promenych
	delete selectionStart;
	delete selectionEnd;
}
function getTextareaSelectionsm()
{
	var textarea = document.forms["clanek"].elements["text"];
	
	if (typeof textarea.selectionStart != 'undefined') {
		var selection = textarea.value.substring(textarea.selectionStart, textarea.selectionEnd);
	} else if (typeof document.selection != 'undefined') {
		var selection = document.selection.createRange().text;
	} else {
		//alert('Bug!');
	}
	return selection;
}


Ve zvýrazněných částech textu si přepiš první hodnotu v hranatých závorkách na jméno (name) formuláře, a do druhé vepiš také jméno (name) textarey. Potom si někam umísti obrázek a nastav mu
<img onlick="insertsm(':-)');return false;" src="obrazek.png" alt="Smajlík" />


Já se v javascriptu moc nevyznám, ale experimentoval jsem, takže je tam možná něco navíc, ale funguje mi to. :-)
shakal
Profil *
Někdo něco lehčího nemá?
MCKAY
Profil
shakal:
Není to tak těžké jak to vypadá. Celý ten dlouhý skript napiš do externího js a přepiš v něm ty zvýrazněné části. Potom si to hoď do stránky a použij. Je to univerzální. Inu jak se to říká? Bez práce nejsou koláče?
shakal
Profil *
Takže když mám tento HTML
<b>Zpráva:</b><br>
<textarea name="message" rows="5" cols="30"></textarea><br>
<br>
<input type="submit" value="Odeslat zprávu">
jak bude JS vypadat?
shakal
Profil *
Nejde mi to, nevím za co přesně mám nahradit
document.forms["clanek"].elements["text"];
MCKAY
Profil
Ok, takže po lopatě: formulář musí vypadat minimálně takto:
<form method="post" action="neco.php" name="diskuse">
<textarea name="message"></textarea>
</form>


a js bude vypadat následovně:
function insertsm(tag, parovy, text, prependText, appendText)
{
    //inicializace proměných
    var textarea = document.forms["diskuse"].elements["message"];

    var startTag = tag;
    var endTag = '';

    if (typeof text == 'undefined') {
        var tagText = getTextareaSelectionsm();
    } else {
        var tagText = text;
    }
    
    if (typeof parovy == 'undefined') {
        var parovy = true;
    }

    if (typeof prependText == 'undefined') {
        var prependText = '';
    }
    
    if (typeof appendText == 'undefined') {
        var appendText = '';
    }
    
    
    //přepsání výchozích hodnot pro specifické tagy
    if (tag == 'url') {
        if (tagText == '') {
            tagText = 'Odkaz';
        }
        var regexp = new RegExp("^((http|https|ftp)\\://)([a-zA-Z0-9\\.\\-]+(\\:[a-zA-Z0-9\\.&%\\$\\-]+)*@)?((25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])|([a-zA-Z0-9\\-]+\\.)*[a-zA-Z0-9\\-]+\\.[a-zA-Z]{2,4})(\\:[0-9]+)?(/[^/][a-zA-Z0-9\\.\\,\\?\\'\\\\/\\+&%\\$#\\=~_\\-@]*)*$");
        var regexp2 = new RegExp("^([a-zA-Z0-9\\.\\-]+(\\:[a-zA-Z0-9\\.&%\\$\\-]+)*@)?((25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])|www\\.([a-zA-Z0-9\\-]+\\.)*[a-zA-Z0-9\\-]+\\.[a-zA-Z]{2,4})(\\:[0-9]+)?(/[^/][a-zA-Z0-9\\.\\,\\?\\'\\\\/\\+&%\\$#\\=~_\\-@]*)*$");
        
        if (regexp.test(tagText)) {
            startTag = '[url=' + tagText + ']';
        } else if (regexp2.test(tagText)) {
            startTag = '[url=http://' + tagText + ']';
        } else {
            startTag = '[url=http://example.com]';
            selectionStart = prependText.length + 5;
            selectionEnd = prependText.length + 23;
        }
    }
        
    //vytvoření textu pro vložení
    if (!parovy) {
        endTag = '';
    }
        
    var text2insert = prependText + startTag + tagText + endTag + appendText;
    
    //vložení:
    textarea.focus();
    
    if (typeof textarea.selectionStart != 'undefined') {
        var start = textarea.selectionStart;
        var end = textarea.selectionEnd;
        
        textarea.value = textarea.value.substr(0, start) + text2insert + textarea.value.substr(end);
        
        //nastaveni kurzoru na spravné misto / vybrani pozadovaneho textu
        if (typeof selectionStart != 'undefined' && typeof selectionEnd != 'undefined') {
            textarea.selectionStart = start + selectionStart;
            textarea.selectionEnd = start + selectionEnd;
        } else {
            if (tagText == '') {
                //skoceni mezi tagy
                textarea.selectionStart = start + prependText.length + startTag.length;
                textarea.selectionEnd = start + prependText.length + startTag.length;
            } else {
                //skoceni za posledni tag
                textarea.selectionStart = start + text2insert.length;
                textarea.selectionEnd = start + text2insert.length;
            }
        }
    }
    else if (typeof document.selection != 'undefined') {
        var range = document.selection.createRange();
        range.text = text2insert;
        
        //nastaveni kurzoru na spravné misto / vybrani pozadovaneho textu
        if (typeof selectionStart != 'undefined' && typeof selectionEnd != 'undefined') {
            range.moveStart('character', -text2insert.length + selectionStart);
            range.moveEnd('character', -text2insert.length + selectionEnd);
        } else {
            if (tagText == '') {
                //skoceni mezi tagy
                range.move('character', -(endTag.length + appendText.length));
            } else {
                //skoceni za posledni tag
                //protoze prohlizec v tomto pripade skoci za posledni tag automaticky, neni treba nic posouvat    
            }
        }
        range.select();
    }

    //unset promenych
    delete selectionStart;
    delete selectionEnd;
}
function getTextareaSelectionsm()
{
    var textarea = document.forms["diskuse"].elements["message"];
    
    if (typeof textarea.selectionStart != 'undefined') {
        var selection = textarea.value.substring(textarea.selectionStart, textarea.selectionEnd);
    } else if (typeof document.selection != 'undefined') {
        var selection = document.selection.createRange().text;
    } else {
        //alert('Bug!');
    }
    return selection;
}


Formulář můžeš jakkoliv stylovat, ale je nezbytné, aby se stále textarea a form jmenovali tak, jak je uvedeno v příkladu.
shakal
Profil *
Zkoušel jsem to přesně tvých nápověd, za které děkuji. Hodím se celej kód jak to mám napsaný.

<form id="formular" name="book" action="diskuse_presmerovani.php" method="post" onsubmit="return book_test();">
<b>Jméno: <?php
session_start(); // startujeme session. Všimněte si, že tento kód je úplně nahoře před jakýmkolik výstupem.
if(isset($_SESSION['prihlasen']) and $_SESSION['prihlasen']==1){
echo "<font color=violet>".$_SESSION['login'] . "</font>";
}else{
echo "";
}

?> </b><br>

<input type="hidden" name="name" size="20" value="
<?php
session_start(); // startujeme session. Všimněte si, že tento kód je úplně nahoře před jakýmkolik výstupem.
if(isset($_SESSION['prihlasen']) and $_SESSION['prihlasen']==1){
echo "".$_SESSION['login'] . "";
}else{
echo "";
}
?>

" >
Vlož kliknutím smajlíka do zprávy: <img onlick="insertsm(':-)');return false;" src="1.gif" />
<br>
<br>
</head>
<body>
<!---<b>Mail:</b><br>
<input name="mail" size="20"><br>
<br>-->
<b>Zpráva:</b><br>
<textarea name="message" rows="5" cols="30"></textarea>

<br>
<input type="submit" value="Odeslat zprávu">


<style>
function insertsm(tag, parovy, text, prependText, appendText)
{
//inicializace proměných
var textarea = document.forms["book"].elements["message"];

var startTag = tag;
var endTag = '';

if (typeof text == 'undefined') {
var tagText = getTextareaSelectionsm();
} else {
var tagText = text;
}

if (typeof parovy == 'undefined') {
var parovy = true;
}

if (typeof prependText == 'undefined') {
var prependText = '';
}

if (typeof appendText == 'undefined') {
var appendText = '';
}


//přepsání výchozích hodnot pro specifické tagy
if (tag == 'url') {
if (tagText == '') {
tagText = 'Odkaz';
}
var regexp = new RegExp("^((http|https|ftp)\\://)([a-zA-Z0-9\\.\\-]+(\\:[a-zA-Z0-9\\.&%\\$\\-]+)*@)?((25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])|([a-zA-Z0-9\\-]+\\.)*[a-zA-Z0-9\\-]+\\.[a-zA-Z]{2,4})(\\:[0-9]+)?(/[^/][a-zA-Z0-9\\.\\,\\?\\'\\\\/\\+&%\\$#\\=~_\\-@]*)*$");
var regexp2 = new RegExp("^([a-zA-Z0-9\\.\\-]+(\\:[a-zA-Z0-9\\.&%\\$\\-]+)*@)?((25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])|www\\.([a-zA-Z0-9\\-]+\\.)*[a-zA-Z0-9\\-]+\\.[a-zA-Z]{2,4})(\\:[0-9]+)?(/[^/][a-zA-Z0-9\\.\\,\\?\\'\\\\/\\+&%\\$#\\=~_\\-@]*)*$");

if (regexp.test(tagText)) {
startTag = '[url=' + tagText + ']';
} else if (regexp2.test(tagText)) {
startTag = '[url=http://' + tagText + ']';
} else {
startTag = '[url=http://example.com]';
selectionStart = prependText.length + 5;
selectionEnd = prependText.length + 23;
}
}

//vytvoření textu pro vložení
if (!parovy) {
endTag = '';
}

var text2insert = prependText + startTag + tagText + endTag + appendText;

//vložení:
textarea.focus();

if (typeof textarea.selectionStart != 'undefined') {
var start = textarea.selectionStart;
var end = textarea.selectionEnd;

textarea.value = textarea.value.substr(0, start) + text2insert + textarea.value.substr(end);

//nastaveni kurzoru na spravné misto / vybrani pozadovaneho textu
if (typeof selectionStart != 'undefined' && typeof selectionEnd != 'undefined') {
textarea.selectionStart = start + selectionStart;
textarea.selectionEnd = start + selectionEnd;
} else {
if (tagText == '') {
//skoceni mezi tagy
textarea.selectionStart = start + prependText.length + startTag.length;
textarea.selectionEnd = start + prependText.length + startTag.length;
} else {
//skoceni za posledni tag
textarea.selectionStart = start + text2insert.length;
textarea.selectionEnd = start + text2insert.length;
}
}
}
else if (typeof document.selection != 'undefined') {
var range = document.selection.createRange();
range.text = text2insert;

//nastaveni kurzoru na spravné misto / vybrani pozadovaneho textu
if (typeof selectionStart != 'undefined' && typeof selectionEnd != 'undefined') {
range.moveStart('character', -text2insert.length + selectionStart);
range.moveEnd('character', -text2insert.length + selectionEnd);
} else {
if (tagText == '') {
//skoceni mezi tagy
range.move('character', -(endTag.length + appendText.length));
} else {
//skoceni za posledni tag
//protoze prohlizec v tomto pripade skoci za posledni tag automaticky, neni treba nic posouvat
}
}
range.select();
}

//unset promenych
delete selectionStart;
delete selectionEnd;
}
function getTextareaSelectionsm()
{
var textarea = document.forms["book"].elements["message"];

if (typeof textarea.selectionStart != 'undefined') {
var selection = textarea.value.substring(textarea.selectionStart, textarea.selectionEnd);
} else if (typeof document.selection != 'undefined') {
var selection = document.selection.createRange().text;
} else {
//alert('Bug!');
}
return selection;
}
</style>
shakal
Profil *
Při kliknutí na smajlíka (1.gif) se ve formuláři nic neobjeví.
Radek9
Profil
shakal:
<img onlick="insertsm(':-)');return false;" src="1.gif" />
<img onClick="insertsm(':-)');return false;" src="1.gif" />
MCKAY
Profil
shakal:
Vkládej kód do . Mám takový dojem, že start session není před jakýmkoliv výstupem.

Je na čase vymyslet něco jednoduššího.

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

<form id="diskuse" action="">
<img src="1.gif" onclick="insertsmajl(':-)')" alt="BBSMajl" />
<textarea id="diskuse"></textarea>
</form>


Řekl bych, že to bude značně jednodušší na implementaci. Nebude to tolik chytré, ale postačí to.
camo
Profil *
Sorry, že sa do toho pletiem, ale ak je to možné poraďte aj mne. Ja nechápem, načo je pri function insertsm(...), taký dlhý argument. Veď funkcii sa predáva pri onclicku len ´:-)´?
Inak povedané načo sú tam tie slová (tag, parovy, text, prependText, appendText)?
Nechápem ich význam. Chápem, že neni nikto povinný, mi to vysvetľovať, ale ak je to možné, tak majte zľutovanie, chcel by som to pochopiť?
Ja zatiaľ chápem z JS len to, že ak onclick predá funkcii dajme-tomu hodnotu 5 a ak tá je definovaná ako
function F (cislo)
, tak sa vlastne vytvorí premenná - cislo, v ktorej bude hodnota 5. Ten zápis
function insertsm(tag, parovy, text, prependText, appendText)
absolutne nechápem. Ani to, prečo sa hneď v treťom riadku premenná tag, hneď ukladá do premennej
var startTag = tag;
.
MCKAY
Profil
camo:
Ten skript je přepsaný tzv. Jush, já v javascriptu neumím zhola nic :-). Jen jsem si trochu hrál a selským rozumem to upravil, myslím, že je nejvyšší čas zmínit, že je tam určitě pár argumentů k ničemu.

Jinak se omlouvám, blbe mi na klávesnii céčko a občas ho tam zapomenu vypsat, viz onlick..:-)
camo
Profil *
Potom je to ale aj tak slušnú výkon, len tak sa hrať s takýmto kódom a ešte to aj funguje. to ja si ešte zrejme počkám.
shakal
Profil *
MCKAY
Ani rvůj script mi nejde. Tady je kód


<form id="formular" name="book" action="diskuse_presmerovani.php" method="post" onsubmit="return book_test();">
<b>Jméno: <?php
session_start(); // startujeme session. Všimněte si, že tento kód je úplně nahoře před jakýmkolik výstupem.
if(isset($_SESSION['prihlasen']) and $_SESSION['prihlasen']==1){
echo "<font color=violet>".$_SESSION['login'] . "</font>";
}else{
echo "";
}

?> </b><br>

<input type="hidden" name="name" size="20" value="
<?php
session_start();
if(isset($_SESSION['prihlasen']) and $_SESSION['prihlasen']==1){
echo "".$_SESSION['login'] . "";
}else{
echo "";
}


?>" >
<script type="text/javascript">
<!--
function insertsmajl(text){
document.getElementById('book').value = document.getElementById('formular').value+text;
}
-->
</script>
Vlož kliknutím smajlíka do zprávy: <img src="1.gif" onclick="insertsmajl(':-)')" alt="BBSMajl" />
<br>
<br>
</head>
<body>
<!---<b>Mail:</b><br>
<input name="mail" size="20"><br>
<br>-->
<b>Zpráva:</b><br>
<textarea name="message" rows="5" cols="30"></textarea>

<br>
<input type="submit" value="Odeslat zprávu">
camo
Profil *
Dajte mu to niekto do
pre tagu
, prosím vás!
shakal
Profil *
<form id="formular" name="book" action="diskuse_presmerovani.php" method="post" onsubmit="return book_test();">
<b>Jméno: <?php
session_start(); // startujeme session. Všimněte si, že tento kód je úplně nahoře před jakýmkolik výstupem.
if(isset($_SESSION['prihlasen']) and $_SESSION['prihlasen']==1){
echo "<font color=violet>".$_SESSION['login'] . "</font>";
}else{
echo "";
}

?> </b><br>

<input type="hidden" name="name" size="20" value="
<?php
session_start();
if(isset($_SESSION['prihlasen']) and $_SESSION['prihlasen']==1){
echo "".$_SESSION['login'] . "";
}else{
echo "";
}


?>" >
<script type="text/javascript">
<!--
function insertsmajl(text){
document.getElementById('book').value = document.getElementById('formular').value+text;
}
-->
</script>
Vlož kliknutím smajlíka do zprávy: <img src="1.gif" onclick="insertsmajl(':-)')" alt="BBSMajl" />
<br>
<br>
</head>
<body>
<!---<b>Mail:</b><br>
<input name="mail" size="20"><br>
<br>-->
<b>Zpráva:</b><br>
<textarea name="message" rows="5" cols="30"></textarea>

<br>
<input type="submit" value="Odeslat zprávu">
camo
Profil *
ale to je to isé, len v zelenom (:-DDDDDD
shakal
Profil *
Sakra, aha :D
A jak se to háže do toho pre tagu?
camo
Profil *
ale nechceš ty náhodou vkladať smaila do id="mesage" a nie do id="formular"?
shakal
Profil *
Ano, potřebuju do message dostat kliknutím na smajlíka 1.gif toto ":-)"
čili já kliknu na smajlíka a v poli message se objeví například ":-)" nebo ":-(" - podle toho na jakýho kliknu ;)
MCKAY
Profil
shakal:
Hele chlape, potřebuješ to mít celé za prvé v tagu <form> a za druhé to textarea musí mít ID takže se nediv že ti to nechodí správně

<script type="text/javascript">
<!--
function insertsmajl(text){
document.getElementById('message').value = document.getElementById('message').value+text;
}
-->
</script>
Vlož kliknutím smajlíka do zprávy: <img src="1.gif" onclick="insertsmajl(':-)')" alt="BBSMajl" />
<br>
<br>
</head>
<body>
<form name="book" action="">
<!---<b>Mail:</b><br>
<input name="mail" size="20"><br>
<br>-->
<b>Zpráva:</b><br>
<textarea id="message" rows="5" cols="30"></textarea>

<br>
<input type="submit" value="Odeslat zprávu">
</form>

Tohle je podstatná část tvého kódu, phpko jsem z toho odmazal, protože je špatně, a plete se. Už mě to přestává bavit.
camo
Profil *
No a tu ti chýbajú úvodzovky
<input type="hidden" name="name" size="20" value="
GeneralDv
Profil
Tady jsem vyhrabal něco 100× jednoduššího:
<script>
function pridejSmajlik(smilie){
    document.gbook.text.focus();
    document.gbook.text.value += smilie + " ";
    document.gbook.text.focus();
}
</script>
<form name="gbook" action="" method="post">
<textarea name="text" rows="10" cols="50"></textarea>
</form>
<a href="javascript:pridejSmajlik(':D')"><img src="smajlik1.gif" alt=":D"></a>
<a href="javascript:pridejSmajlik('xD')"><img src="smajlik1.gif" alt="xD"></a>
<a href="javascript:pridejSmajlik('xP')"><img src="smajlik1.gif" alt="xP"></a>
<a href="javascript:pridejSmajlik(':P')"><img src="smajlik1.gif" alt=":P"></a>
<a href="javascript:pridejSmajlik(':)')"><img src="smajlik1.gif" alt=":)"></a>
camo
Profil *
no ale ty vo funkcii predávaš onClick formuláru a nie tagu textarea, ktorý musí mať name. Tag form nemá pokiaľ viem value, majú ho iba jeho potomci, v tvojom prípade textarea.
function insertsmajl(text){
document.getElementById('book').value = document.getElementById('formular').value+text;


function insertsmile(smile){
document.getElementById(´message').innerhtml = smile
}

Toto by sa malo odohrať na úrovni JavaScriptu, čo už potom pošleš PHP a ako to tam spracuješ, to sem myslím nepatrí.
Radek9
Profil
camo:
Textarea nemá innerHTML, ale value.

Jinak. Všichni tady pletete všechno dohromady. Aby šla textare odeslat, musí být obalena ve <form>u! A potom není problém oboum nastavit name.
function insertsmajl(smajl){
document.name_formu.name_textarey.value += smajl+" ";
}
MCKAY
Profil
Radek9:
Existuje nevalidní způsob jak odeslat textareu bez <form>u, ale podporuje to jen chytrý prohlížeč. <input type="submit" action=".." />, osobně nejsem ale zastáncem takové prasárny..:-)
camo
Profil *
Radek
No tak som zase múdrejší a ospravedlňujem sa, že to pletiem.
No a ty samozrejme chceš aby sa smile zobrazil tam kde chceš ty a potom treba robiť s tým value+text, ale to si už netrúfam riešiť.
takže
1.doplň si tam ten form
2. úvodzovky
3. nepredávaj to formuláru, ale tomu message.
camo
Profil *
Shakal
Radek tomu tu asi rozumie najlepšie, takže si tu funkciu prepíš tak ako napísal a snáď to bude fungovať.
function insertsmajl(smajl){
document.name_formu.name_textarey.value += smajl+" ";
}
camo
Profil *
Radek

Len taká otázočka - cez getElementById alebo tagName sa ku tej textaree dostať nedá?
« 1 2 »

Vaše odpověď

Mohlo by se hodit

Neumíte-li správně určit příčinu chyby, vkládejte odkazy na živé ukázky.
Užíváte-li nějakou cizí knihovnu, ukažte odpovídajícím, kde jste ji vzali.

Užitečné odkazy:

Prosím používejte diakritiku a interpunkci.

Ochrana proti spamu. Napište prosím číslo dvě-sta čtyřicet-sedm:

0