[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
 
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!
 
write a javascript, that gets used when the user clicks submit, onbuttonpress or whatever, and tell it to set the values back to nill.
 
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?
 
Well, i believe you have to use the form name, as so: document.formname.submit().
 
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.
 
You should be able to use submit for it just like before. onClick should work the same.
 
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?
 
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

No members online now.

Latest profile posts

Also Hi EP and people. I found this place again while looking through a oooollllllldddd backup. I have filled over 10TB and was looking at my collection of antiques. Any bids on the 500Mhz Win 95 fix?
Any of the SP crew still out there?
Xie wrote on Electronic Punk's profile.
Impressed you have kept this alive this long EP! So many sites have come and gone. :(

Just did some crude math and I apparently joined almost 18yrs ago, how is that possible???
hello peeps... is been some time since i last came here.
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.

Forum statistics

Threads
62,015
Messages
673,494
Members
5,621
Latest member
naeemsafi
Back