Welcome to WebmasterWorld Guest from 54.226.2.31

Forum Moderators: open

Message Too Old, No Replies

Submit then clear

a javascript question

     

ggrot

11:23 pm on Apr 17, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Alright, I have this little form whose target is actually another frame, so when the submit button is pressed, the form itself does not reload. I would like to have javascript clear out the value of one of the text fields after submitting. At the moment, the code looks something like this:

...
<textarea cols="24" rows="3" name="message"></textarea>
...
<input type="submit" name="s" value="Submit" onClick="document.f.message.value='';">

Where f is the name of the form in question. This little bit of javascript ends up clearing the message field and then posting the results instead of the other way around. Is there any way to get the form submission and then have the message field cleared?

DrDoc

12:28 am on Apr 18, 2002 (gmt 0)

WebmasterWorld Senior Member drdoc is a WebmasterWorld Top Contributor of All Time 10+ Year Member



There are two ways to solve the problem:

Change the submit button to a BUTTON type. Then point the OnClick even to a JavaScript function that looks something like this:

function myfunc() {
document.f.submit();
document.f.message.value="";
}

The other way to solve it is to have the document in the other frame clear the field.

parent.name_of_frame.document.f.message.value="";

ggrot

1:42 am on Apr 18, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, this particular feature would be just a convenience, I wouldn't want to break the form for non-javascript users to get the field cleared, therefore the first solution is not a possiblity.

The document loaded in the other frame is actually part of a separate domain, I tried this solution and IE at least complained to me about security and killed the javascript request.

Any other ideas or is this impossible given the new constraints?

DrDoc

8:03 pm on Apr 18, 2002 (gmt 0)

WebmasterWorld Senior Member drdoc is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Well, then there's pretty much just two more solutions:

1) When the other frame has loaded, let it reload (or load a new page) in the first frame (using 'parent.name_of_frame.location.href')

2) in the OnClick for the submit button, do something like OnClick="setTimeOut('myFunc()',1000)" and use this script:

function myFunc() {
document.f.message.value = "";
}

That way there's a 1000 millisecond delay before the form is cleared, and the form should've been posted by then.

 

Featured Threads

Hot Threads This Week

Hot Threads This Month