[HTML]/[Javascript] Empty field on submit

Glaanieboy

OSNN Veteran Addict
Joined
6 Mar 2002
Messages
2,628
OK, on my website (http://glaanieboy.dyndns.org/design) I have a shoutbox. The shouts are placed in an <iframe>, but the form is on the main page. The form has a target="<iframe_name>" and it works well. But, when I click submit, the text I filled in the Message box stays and I want it to dissappear, so only the name is visible (the name is loaded by a cookie btw).
I hope you know what I mean, if not, explain what you don't understand and I'll try to clarify.

I remember asking this question on the 'old' NTFS a year ago when I had my old, sluggish shoutbox, but I lost the files, so I can't see if it was solved back then :p
 

Glaanieboy

OSNN Veteran Addict
Joined
6 Mar 2002
Messages
2,628
Alright, i have done a little more research, and I have found a rather large list with javascript thingies here: http://www.juicystudio.com/tutorial/javascript/document.asp, but to be honest, I don't have a clue how to handle it. The problem here is, is that there are two pages involved, one with the data and one with the form. Somehow, I want that when the data page is loaded, one field in the other page with the form will get erased. I know you can do that by using the onLoad function in the body element on the data page, but I have no idea how. Help me!
 

X-Istence

*
Political Access
Joined
5 Dec 2001
Messages
6,498
write a javascript, that gets used when the user clicks submit, onbuttonpress or whatever, and tell it to set the values back to nill.
 

Glaanieboy

OSNN Veteran Addict
Joined
6 Mar 2002
Messages
2,628
X-Istence said:
write a javascript, that gets used when the user clicks submit, onbuttonpress or whatever, and tell it to set the values back to nill.
OK, I now have changed the submit button in a normal button and added a new value called onClick="javascript:clearText(shout)"> (shout is the name if the field to be deleted). I use this function:
Code:
function clearText(incoming){
   document.form.submit();
   incoming.value = "";
}

It submits, and the new shout appears on the shoutbox. Nothing else. I added a alert('bla'); function to it, to see if it does something after it submits, but no alert box. When I leave the document.for.submit() thingy out, it clears the field correctly. How can I solve this?
 

X-Istence

*
Political Access
Joined
5 Dec 2001
Messages
6,498
Well, i believe you have to use the form name, as so: document.formname.submit().
 

Glaanieboy

OSNN Veteran Addict
Joined
6 Mar 2002
Messages
2,628
Then I have one tiny problem. Because I rebranded the button as a "button", instead of "submit", it doesn't respond to the enter key, I have to click the button to submit it. I know there was a solution for it on the old NTFS, but I forgot. I believe it was also a javascript thingy.
 

X-Istence

*
Political Access
Joined
5 Dec 2001
Messages
6,498
You should be able to use submit for it just like before. onClick should work the same.
 

Glaanieboy

OSNN Veteran Addict
Joined
6 Mar 2002
Messages
2,628
I now have this:
Code:
function clearText(incoming){
  document.shoutform.submit();
  incoming.value = "";
}

and
Code:
<form method="post" action="shout.php?action=newmess" target="shoutbox" name="shoutform">
Name:<br><input type="text" name="name" value="">
Message:<br><input type="text" name="shout" value=""><br>
<input type="button" value="Shout!" onClick="javascript:clearText(shout);">
</form>

This works (except for the Enter/Return-key bit), but when I use your suggestion and change the button type to "submit", it only clears the text, nothing else. I have tried changing the onClick to onSubmit, then I tried placing the onSubmit in the <form>, I have tried commenting the submit bit in the function out, but it all didn't work.
Suggestions?
 

ignipotentis

OSNN Addict
Joined
25 Mar 2004
Messages
127
don't use a button. use a standard hyperlink. <a href="foo" onClick="bar"><img...></a>

You will be able to tab to your "button" and use the enter key.

Hope this helps.
 

Members online

Latest profile posts

Electronic Punk wrote on Sazar's profile.
Rest in peace my friend, been trying to find you and finally did in the worst way imaginable.
Terrahertz wrote on Electronic Punk's profile.
Yo fellas!
Electronic Punk wrote on Sazar's profile.
Where are you buddy?
Perris Calderon wrote on Electronic Punk's profile.
Hey EP! All good with me, applying for Microsoft MVP right now, should have done this a while ago.

Notifications don't work, I only found your response by coming back to hunt up some threads, if you want, give me your email address so we can keep in touch easier!
Perris Calderon wrote on Electronic Punk's profile.
EP, glad to see you come back and tidy up...did want to ask a one day favor, I want to enhance my resume , was hoping you could make me administrator for a day, if so, take me right off since I won't be here to do anything, and don't know the slightest about the board, but it would be nice putting "served administrator osnn", if can do, THANKS

Been running around Quora lately, luv it there!

Forum statistics

Threads
61,997
Messages
673,411
Members
5,590
Latest member
AntonioPR