# HTML/JavaScript ?

**URL:** https://boards.straightdope.com/t/html-javascript/150258
**Category:** Factual Questions
**Created:** [January 22, 2003, 5:45pm UTC](https://boards.straightdope.com/t/html-javascript/150258 "2003-01-22T17:45:40Z")
**Posts on this page:** 6
**Page:** 2

<div class="post-metadata">

### Author: ![Q.E.D](https://avatars.discourse-cdn.com/v4/letter/q/51bf81/32.png) [@Q.E.D](https://boards.straightdope.com/u/Q.E.D)
#### Post date: [January 23, 2003, 2:52am UTC](https://boards.straightdope.com/t/html-javascript/150258/21 "2003-01-23T02:52:22Z")

</div>

If method=“get” gave an error, then you can try method=“post”. I don’t know too much about javascript. All of my forms to date have made calls to CGI scripts. If you need help with Perl or PHP, I’m your boy. And since I bring it up, it seems likely that the search is being done by a CGI script or something along those lines. Why not forgo the javascript entirely, and simply pass the search parameter from the FORM directly to the script? I imagine you don’t want every Tom, Dick and Harry having the URL in question, but if you **can** post it, it might help for us to see it.

---

<div class="post-metadata">

### Author: ![Monstre](https://avatars.discourse-cdn.com/v4/letter/m/e274bd/32.png) [@Monstre](https://boards.straightdope.com/u/Monstre)
#### Post date: [January 23, 2003, 4:18am UTC](https://boards.straightdope.com/t/html-javascript/150258/22 "2003-01-23T04:18:07Z")

</div>

**enipla**

Modify your form tag to this:

```auto

<FORM name="frmSearch" onSubmit="legalpre(); return false">

```

_onSubmit_ is an event handler, and several of the event handlers have special uses of return values – although there does not appear to be a consistent rhyme or reason for them.

The onSubmit event handler generally defaults to a request to submit the form (using a normal submission method). Since you are trying to override the normal submission and just call a javascript function instead, use the “return false” clause (at the end of the event handler’s code) to prevent the form from actually being “submitted”.

---

<div class="post-metadata">

### Author: ![enipla](https://avatars.discourse-cdn.com/v4/letter/e/54ee81/32.png) [@enipla](https://boards.straightdope.com/u/enipla)
#### Post date: [January 23, 2003, 2:09pm UTC](https://boards.straightdope.com/t/html-javascript/150258/23 "2003-01-23T14:09:23Z")

</div>

Thanks Monstre & Q.E.D

The solution was a combo of your answers.

\<FORM name=“frmSearch” onSubmit=“legalpre(); return false” method=“get”\>

Thanks again

enipla - Alpine

---

<div class="post-metadata">

### Author: ![Q.E.D](https://avatars.discourse-cdn.com/v4/letter/q/51bf81/32.png) [@Q.E.D](https://boards.straightdope.com/u/Q.E.D)
#### Post date: [January 23, 2003, 2:54pm UTC](https://boards.straightdope.com/t/html-javascript/150258/24 "2003-01-23T14:54:07Z")

</div>

You’re quite welcome 🙂

---

<div class="post-metadata">

### Author: ![Monstre](https://avatars.discourse-cdn.com/v4/letter/m/e274bd/32.png) [@Monstre](https://boards.straightdope.com/u/Monstre)
#### Post date: [January 23, 2003, 3:19pm UTC](https://boards.straightdope.com/t/html-javascript/150258/25 "2003-01-23T15:19:07Z")

</div>

> [@](#):
>
> \*Originally posted by enipla \*  
> \*\*Thanks Monstre & Q.E.D
> 
> The solution was a combo of your answers.
> 
> \<FORM name=“frmSearch” onSubmit=“legalpre(); return false” method=“get”\>  
> \*\*

Actually, you shouldn’t even need the ‘method=“get”’ part, since the “return false” clause means that you are preventing the form submission itself.

I tested it without any method or action attributes, and it worked well. Thanks to **NotMrKnowItAll** for making the test files easy to set up (and **enipla** , I did put in your change that initially “broke” it, too – so I was able to replicate the problem exactly as you had described it).

---

<div class="post-metadata">

### Author: ![pestie](https://avatars.discourse-cdn.com/v4/letter/p/e5b9ba/32.png) [@pestie](https://boards.straightdope.com/u/pestie)
#### Post date: [January 23, 2003, 5:17pm UTC](https://boards.straightdope.com/t/html-javascript/150258/26 "2003-01-23T17:17:46Z")

</div>

I’ll bet anything this is actually an issue of context. The definition of “parent” changes depending on where the function is called from. If you call from onSubmit “parent” probably references something different from calling it from onClick. The function IS being called in both cases.

Incidentally, rather than doing this:

onSubmit=“whatever(); return false”

I like to do this:

onSubmit=“return whatever();”

and I make sure my function returns false (or true, or what have you.) I just find it easier to read.

[Previous page](https://boards.straightdope.com/t/html-javascript/150258.md?page=1)
