homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

Submit then clear
a javascript question

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

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?



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

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() {

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



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

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?


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

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.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved