take first letter out of a form-tag

merlin's picture

They have: 410 posts

Joined: Oct 1999

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's picture

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>
&lt;script language=javascript&gt;
function do_sumthin() {
  tmp = my.value;
  blah.innerHTML=blah.innerHTML + tmp.substring(0,1);
  my.value=tmp.substring(1,tmp.length)
}
&lt;/script&gt;
</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's picture

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! Smiling )

Mark Hensler's picture

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's picture

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... Sad any ideas how to solve that?

anyway thank you! Laughing out loud

They have: 21 posts

Joined: Nov 2000

To write to layers in netscape, you must use layername.document.write. Try this:

<html>
<head>
&lt;script language=javascript&gt;
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)
  }
}
&lt;/script&gt;
</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's picture

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... Wink ). 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?

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 Smiling.

Jon.

Jon Steele -
EverySolution.com

merlin's picture

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... Sad

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.