# javascript question - .submit()

**URL:** https://boards.straightdope.com/t/javascript-question-submit/371752
**Category:** Factual Questions
**Created:** [September 7, 2006, 5:26am UTC](https://boards.straightdope.com/t/javascript-question-submit/371752 "2006-09-07T05:26:35Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Improv\_Geek](https://avatars.discourse-cdn.com/v4/letter/i/b3f665/32.png) [@Improv\_Geek](https://boards.straightdope.com/u/Improv_Geek)
#### Post date: [September 7, 2006, 5:26am UTC](https://boards.straightdope.com/t/javascript-question-submit/371752/1 "2006-09-07T05:26:35Z")

</div>

Yes I know frames suck, but for the web app I’m trying to build they are necessary for the design I’m aiming for. What I need to do is in one frame, submit a form and then clear a value in that form. What I’m discovering though is that when I run ‘this.form.submit()’ all code after it is skipped, is there any way to run code after running a .submit()?

Thanks guys

-IG

---

<div class="post-metadata">

### Author: ![Stealth\_Potato](https://avatars.discourse-cdn.com/v4/letter/s/d78d45/32.png) [@Stealth\_Potato](https://boards.straightdope.com/u/Stealth_Potato)
#### Post date: [September 7, 2006, 6:05am UTC](https://boards.straightdope.com/t/javascript-question-submit/371752/2 "2006-09-07T06:05:19Z")

</div>

In both Mozilla Firefox and Internet Explorer, a runtime error in a script terminates the current script, so it’s not anything inherent in form.submit() that’s disallowing subsequent statements from being executed. Also, in both FF and IE, in the global context, “this” evaluates to the current window object, not to the document, which is what you would want if you wanted to access your form; this would explain the error, as you are trying to access a property (the submit method) of an undefined object (this.form).

The window object does _contain_ the document property - however, you can simply refer to the document directly; using “this” would be unnecessary. You should probably be doing something like this:

```auto

document.forms.nameofyourform.submit();

// or...

document.getElementById("formid").submit();

```

I think both of these methods will work in both the FF and IE DOMs.

---

<div class="post-metadata">

### Author: ![Stealth\_Potato](https://avatars.discourse-cdn.com/v4/letter/s/d78d45/32.png) [@Stealth\_Potato](https://boards.straightdope.com/u/Stealth_Potato)
#### Post date: [September 7, 2006, 6:15am UTC](https://boards.straightdope.com/t/javascript-question-submit/371752/3 "2006-09-07T06:15:04Z")

</div>

Also, note that in the document.forms collection, you can access your form both by its “id” attribute and its “name” attribute, whereas with getElementById you can use both only in Internet Explorer - in Firefox, only the correct “id” attribute will work. This is just a case of IE being wonky.

For example:

```auto

<form name="myform" id="myformid"></form>

<script type="text/javascript">
document.forms.myform.submit(); // works

document.forms.myformid.submit(); // works

document.getElementById("myformid").submit(); // also works

document.getElementById("myform").submit(); // works only in Internet
                                                // Explorer, not in Firefox
</script>

```
