take first letter out of a form-tag
what i'd like to do:
i have an
-tag. when the user writes something in it, it takes the first letter out (without deleting it, of course) and puts it somewhere on a specified area on the page.
for example:
it takes the 'w' out of my message-field and puts it on the very top of the page.
i think this shoud be doable? any ideas?
[Edited by alibababa on Feb. 01, 2001 at 06:14 AM]
Mark Hensler posted this at 21:57 — 1st February 2001.
He has: 4,048 posts
Joined: Aug 2000
when would you take the letter out? onBlur? onChange? onClick?
anyway.... I used onClick with a button
<html>
<head>
<script language=javascript>
function do_sumthin() {
tmp = my.value;
blah.innerHTML=blah.innerHTML + tmp.substring(0,1);
my.value=tmp.substring(1,tmp.length)
}
</script>
</head>
<body>
<span id=blah></span>
<BR>
<input type=text id=my>
<input type=button value="Send it away!" onClick="do_sumthin()">
</body>
</html>
Mark Hensler
If there is no answer on Google, then there is no question.
merlin posted this at 08:21 — 2nd February 2001.
They have: 410 posts
Joined: Oct 1999
thanks, mark.
but i get an error:
'my' is not defined...
another question: what's the span-tag for?
i need the whole thing onChange but that i can do on my own (at least one thing! )
Mark Hensler posted this at 09:03 — 2nd February 2001.
He has: 4,048 posts
Joined: Aug 2000
I'm using IE5 and it works for me. Try stuff like document.my.value or put it in a form and try form_name.my.value
the span tag... notic the ID property? I use it later to put the text from the textbox into the HTML page. The innerHTML is used to address the text between the span tags. Here, I added to it with each click.
Mark Hensler
If there is no answer on Google, then there is no question.
merlin posted this at 09:21 — 2nd February 2001.
They have: 410 posts
Joined: Oct 1999
yup, it's working! i added the form_name to the my-stuff...
but, it's only working in ie5, not in netscape... any ideas how to solve that?
anyway thank you!
jonsteele posted this at 21:07 — 2nd February 2001.
They have: 21 posts
Joined: Nov 2000
To write to layers in netscape, you must use layername.document.write. Try this:
<html>
<head>
<script language=javascript>
function do_sumthin() {
tmp = my.value;
if (document.layers){
document.layers[blah].document.open();
document.layers['blah'].document.write(blah.innerHTML + tmp.substring(0,1));
document.layers['blah'].document.close();
}
else{
document.all['blah'].innerHTML=blah.innerHTML + tmp.substring(0,1);
my.value=tmp.substring(1,tmp.length)
}
}
</script>
</head>
<body>
<span id=blah></span>
<BR>
<input type=text id=my>
<input type=button value="Send it away!" onClick="do_sumthin()">
</body>
</html>
Jon Steele -
EverySolution.com
merlin posted this at 13:58 — 5th February 2001.
They have: 410 posts
Joined: Oct 1999
still not working in nn.
i tried it with quite a lot of possibilities of combinations (what shall i do, don't know java... ). my last try:
function takeoutfirstletter() {
firstletter.innerHTML = "";
tmp = document.wettbewerb.titel.value;
if (document.layers){
document.layers['firstletter'].document.open();
document.layers['firstletter'].document.write(firstletter.innerHTML + tmp.substring(0,1));
document.layers['firstletter'].document.close();
} else {
document.all['firstletter'].innerHTML = firstletter.innerHTML + tmp.substring(0,1);
titel.value=tmp.substring(1,tmp.length)
}
}
got errors from 'takeoutfirstletter' not defined via 'document.all' has no properties to firstletter not defined.
any ideas what i'm doing wrong here?
jonsteele posted this at 23:06 — 5th February 2001.
They have: 21 posts
Joined: Nov 2000
You can't use firstletter.innerHTML in the document.layers section. NN won't recognize that.
Also, move the first line of the function into else{}.
NS6 has a different way of dealing with layers. This won't work in NS6.
Good luck on the rest .
Jon.
Jon Steele -
EverySolution.com
merlin posted this at 12:45 — 6th February 2001.
They have: 410 posts
Joined: Oct 1999
hm, it still doesnt do what i'd like it to...
anyway, it's an optional feature, so...
thank you mark and jon for your support!
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.