Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Clear *After* Submit ? 3

Status
Not open for further replies.

TommyB44

Technical User
Jun 16, 2005
76
0
0
GB
Hi All,

the following code is clearing my form before it submits not after how do i fix this ?
Code:
<iframe src="messages.asp" height="75%" width="100%" frameborder="0" name="view"></iframe>
<br>
<div align="left">
<FORM  name="fsend" METHOD="Post" ACTION="messages.asp" target="view">
<b>
Name: <INPUT TYPE="Text" NAME="handle" value="" maxlength="10" size="10">&nbsp;&nbsp;&nbsp;
Message: <INPUT TYPE="Text" NAME="msg" value="" maxlength="600" size="45">&nbsp;&nbsp;
<INPUT TYPE="Submit" VALUE="Send" style='background:green;color:white;font:bold' onclick='checkit();'>
</b>
</div>
</form>
<script>
function checkit(){
if (document.fsend.msg.value=="" || document.fsend.handle.value=="")
alert("Enter Value");
clear();
}
function clear(){
//document.fsend.reset();
document.fsend.submit();
document.fsend.msg.value="";
}
</script>

any ideas would be great thanks.
 
Why are you trying to clear the form?

submit() takes a couple of seconds to happen and it is probably a separate thread so execution of the rest of the function does not wait for submit() to be done.

By the way, you probably want to follow your if-statement in checkIt() with an else and put the call to clear() in there. Otherwise, even if the user has not entered a value for msg or handle, the form submission will occur.

'hope this makes sense.

--Dave
 
Since you are posting your data to the iframe why dont you try letting the code in that frame handle the clearing of the parent frame?

The submission would complete going to the iframe, the data is displayed/processed and then the command can be executed to clear the first form.

Paranoid? ME?? WHO WANTS TO KNOW????
 
Because the page doesn't refresh and only changes the messages.asp, without the clear function the message the user types into the message input box stays where it is, I don't mind the value of the name input box staying where it is, but the value of the message input box needs emptying, but only after it has submitted, otherwise there is nothing to submit.

Thanks.
 
Ah, I didn't notice that you were posting to an IFRAME. I see now.

niteowl's response should work for you.

--Dave
 
O.K,

for anyone else that might get the same problem, I added the following code to the iframe src page (messages.asp).

Code:
<script>
var t = parent.document.getElementById('fsend');
t.msg.value="";
</script>

should be cross browser ?...

anyway, thanks theniteowl, I probably wouldn't even of given that a thought.
 
actually, it doesn't clear in firefox, Shame, still one step closer.
 
Try, simply:

parent.document.fsend.msg.value="";

--Dave
 
Yep, that worked in both IE and FireFox, Thanks.
 
actually, it doesn't clear in firefox, Shame, still one step closer.
The reason that .getElementById() didn't work for you is because you had defined a name for that element, but not an id. If you prefer to use name to define the element but want to avoid those "use w3c standard getElementById() blah blah blah" warnings in firefox then you could modify LookingForInfo's code to this:

[tt]parent.document.forms["fsend"].elements["msg"].value = "";[/tt]

-kaht

...looks like you don't have a job, so why don't you get out there and feed Tina.
headbang.gif
[rockband]
headbang.gif
 
I see it should have been <form id="fsend"....


Thanks Kaht.
 
That's correct, or you could have completely bypassed the form and gave the textbox an id instead:

<INPUT TYPE="Text" ID="msg".....
-using-
document.getElementById("msg").value = "";

When defining elements using id you must give them all unique individual names. For this reason, you do not have to specify which form an element falls under because only 1 item with that id will exist on the entire page.

-kaht

...looks like you don't have a job, so why don't you get out there and feed Tina.
headbang.gif
[rockband]
headbang.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top