.dsy:it.
Show 150 posts per page

.dsy:it. (http://www.dsy.it/forum/)
- Tech (http://www.dsy.it/forum/forumdisplay.php?forumid=189)
-- [Javascript] (http://www.dsy.it/forum/showthread.php?threadid=22209)


Posted by Napolux on 20-10-2005 20:10:

[Javascript]

Ciao a tutti...

Dovrei fare una cosa del genere:

- Inserire un testo in una textarea
- Selezionare parte del testo
- A questo testo selezionato aggiungere all'inizio e alla fine una @ premendo un bottone.

Fino al bottone ci arrivo, al click faccio eseguire una funzione, ma le @ vengono messe alla fine della textarea...

Come fare per metterle all'inizio e alla fine del testo *selezionato* ???

__________________
Napolux.com


Posted by 0m4r on 20-10-2005 20:38:

scusa, io non so darti una risposta... ma non riesci a dare un occhiata a come funzionano le form dei forum (oviamente quelli che te lo permettono)???

è un'idea... scusa se non è la risposta che cercavi...

__________________
http://www.twitter.com/0m4r


Posted by yeah on 20-10-2005 23:03:

Ho usato un pò javascript qualche tempo fa e per quel che mi ricordo non mi sembra una cosa fattibile, poichè credo che la selezione del testo sia esterna a javascript stesso, ma gestita dall'interfaccia grafica.

Nessuna garanzia però :)

__________________
?


Posted by Napolux on 21-10-2005 10:23:

Originally posted by 0m4r
scusa, io non so darti una risposta... ma non riesci a dare un occhiata a come funzionano le form dei forum (oviamente quelli che te lo permettono)???

è un'idea... scusa se non è la risposta che cercavi...


si' ho provato, ma vorrei capire per bene come funziona, non fare copia e incolla...

che poi non funziona sempre...

__________________
Napolux.com


Posted by ripe on 21-10-2005 11:42:

Io lo so fare con IE, ma purtroppo non conosco il modello selection di Firefox, quindi dubito che ti sia utile...

__________________
«And if you ever smell christian blood up in the mountains, then get your axe and chop them down!»


Posted by Napolux on 21-10-2005 21:30:

Originally posted by ripe
Io lo so fare con IE, ma purtroppo non conosco il modello selection di Firefox, quindi dubito che ti sia utile...


Gia' IE sarebbe un passo avanti...

__________________
Napolux.com


Posted by ripe on 22-10-2005 11:02:

Ok, allora il codice - scritto in maniera moooolto sporca :D - è semplicemente questo:

code:
<script> function marcaSelezione() { var selezione = document.selection.createRange().text; if (selezione != "") document.selection.createRange().text = "@" + selezione + "@"; } </script> <input type="button" onClick="marcaSelezione()" value="Inserisci" /><br /> <textarea>Testo da selezionare</textarea>


Purtroppo non ho ancora sperimentato con Firefox, perché sulle selezioni in modello di Mozilla è ancora un pò fumoso... ;)

__________________
«And if you ever smell christian blood up in the mountains, then get your axe and chop them down!»


Posted by Hamelin on 22-10-2005 11:25:

Più che il modello di Mozilla direi il DOM standard... o sbaglio?

__________________
Bjarne Stroustrup: "I have always wished for my computer to be as easy to use as my telephone; my wish has come true because I can no longer figure out how to use my telephone."
Andrew S. Tanenbaum: "Never underestimate the bandwidth of a station wagon full of tapes hurtling down the highway."
Edsger Dijkstra: "Computer Science is no more about computers than astronomy is about telescopes."
Robert Firth: "One of the main causes of the fall of the Roman Empire was that, lacking zero, they had no way to indicate successful termination of their C programs."
Donald Knuth: "A mathematical formula should never be 'owned' by anybody! Mathematics belong to God."


Posted by ripe on 22-10-2005 11:44:

Originally posted by Hamelin
Più che il modello di Mozilla direi il DOM standard... o sbaglio?


Non so, il windows.getSelection() e document.getSelection() li hanno invertiti un pò di volte... comunque ho detto, non ci capisco nulla! :asd:

__________________
«And if you ever smell christian blood up in the mountains, then get your axe and chop them down!»


Posted by Napolux on 23-10-2005 09:58:

deng iu!

__________________
Napolux.com


All times are GMT. The time now is 22:56.
Show all 10 posts from this thread on one page

Powered by: vBulletin Version 2.3.1
Copyright © Jelsoft Enterprises Limited 2000 - 2002.