Javascript - Please help me!!

Status
Not open for further replies.

prasanna7287

Broken In
I am making a small project.. i have some doubt..

I have a HTML text-area box, and a button, when i type in some text in the box say Hello, then when i press the button, the words in the text-area box must become 1Hello1

Can anybody help me with this ?? Plz..

Prasanna.
 

mod-the-pc

Back to School Mr. Bean !
<HTML>
<BODY>
<FORM NAME=FORM1>
<INPUT TYPE=TEXT NAME=TEXT1 VALUE='HELLO'>
<BR>
<INPUT TYPE=BUTTON NAME=SUBMIT1 VALUE=SUBMIT onClick="document.FORM1.TEXT1.value='1'+document.FORM1.TEXT1.value+'1';">
</FORM>
</BODY>
</HTML>
 
OP
P

prasanna7287

Broken In
thanks for the quick reply, but supposing.. in the word Hello, if i am going to highlight/select (using my mouse) only the letters Hello, then i would need the output as 1Hell1o ..

can u get this one done for me mate.. am sorry.. am a n00b at java scripting :(

Prasanna.
 

mod-the-pc

Back to School Mr. Bean !
Try this,
<HTML>
<script language=javascript>
function getActiveText()
{
totalText = document.FORM1.TEXT1.value;
selectedText = document.selection.createRange().text ;
if (selectedText != '')
{
totalText = totalText.replace(selectedText,'1'+selectedText+'1')
document.FORM1.TEXT1.value = totalText;
}
return true;
}
</script>
<BODY>
<FORM NAME=FORM1>
<INPUT TYPE=TEXT NAME=TEXT1 VALUE='HELLO'>
<BR>
<INPUT TYPE=BUTTON NAME=SUBMIT1 VALUE=SUBMIT onClick="getActiveText();">
</FORM>
</BODY>
</HTML>
 
Status
Not open for further replies.
Top Bottom