• 0
Sign in to follow this  
Guest psychochandy

Mostrar Texto Selecionado Num Input?

Question

Guest psychochandy

Como posso fazer para que ao selecionar um texto, não todo o texto, me mostrasse um alert com o texto q eu selecionei? tentei com o atributo onSelect mas não vai, ele pega toda a frase e aí não me servi! Como fazer isso?

alguém por favor, me ajude?

grato.

Share this post


Link to post
Share on other sites

3 answers to this question

Recommended Posts

  • 0

tenta assim:

<html>
<head>
<script language="JavaScript">
<!--
//by john doe
function alertSel(){
var sRange = document.selection.createRange();
if(sRange.text.length!=0){
alert(sRange.text)
}
}
-->
</script>
</head>
<body>
<input type="text" onmouseup="alertSel()">
</body>
</html>

Share this post


Link to post
Share on other sites
  • 0
tenta assim:

<html>
<head>
<script language="JavaScript">
<!--
//by john doe
function alertSel(){
var sRange = document.selection.createRange();
if(sRange.text.length!=0){
alert(sRange.text)
}
}
-->
</script>
</head>
<body>
<input type="text" onmouseup="alertSel()">
</body>
</html>

Só toma cuidado que isso não funciona em todos os browsers... sad.gif

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this