473,569 Members | 2,764 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

<select onchange="this. form.submit()"> and Submit button on one form

How to have <select onchange="this. form.submit()"a nd also a Submit
button on one form?

I have something like this:

<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post"
enctype="multip art/form-data" name="form1">
<select onchange="this. form.submit();" name="prod">
<option value="">Select product</option>
<option value="12">abc</option>
</select>

<input type="submit" name="submit" value="Submit" />
</form>

In the above code, this.form.submi t() within the <selectdoes not
have any effect. The submit button works fine.

But when I removed the submit button from the <form>, the
this.form.submi t() works fine.

How can I have both form submissions within a single form?

Thanks!
Sep 16 '08 #1
14 75462
On Sep 15, 10:06*pm, white lightning <crescent...@ya hoo.comwrote:
How to have <select onchange="this. form.submit()"a nd also a Submit
button on one form?

I have something like this:

<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post"
enctype="multip art/form-data" name="form1">
* <select onchange="this. form.submit();" name="prod">
* * * * <option value="">Select product</option>
* * * *<option value="12">abc</option>
* </select>

* <input type="submit" name="submit" value="Submit" />
</form>

In the above code, this.form.submi t() within the <selectdoes not
have any effect. The submit button works fine.

But when I removed the submit button from the <form>, the
this.form.submi t() works fine.

How can I have both form submissions within a single form?

Thanks!
What do you suppose 'this' refers to in your code?

Try:

document.forms[x].submit()

Replace x with the correct index for your form, if your form is the
first in the document, it would be
document.forms[0].submit()


Sep 16 '08 #2
>
What do you suppose 'this' refers to in your code?

Try:

document.forms[x].submit()

Replace x with the correct index for your form, if your form is the
first in the document, it would be
document.forms[0].submit()
No that also does not work!
Sep 16 '08 #3
On Sep 16, 8:06*am, white lightning <crescent...@ya hoo.comwrote:
But when I removed the submit button from the <form>, the
this.form.submi t() works fine.
The name of your submit button is 'submit' which is overriding the
form's submit function. Rename the button to something else, it should
work fine:

<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post"
enctype="multip art/form-data" name="form1">
<select onchange="this. form.submit();" name="prod">
<option value="">Select product</option>
<option value="12">abc</option>
</select>

<input type="submit" name="mySubmitB utton" value="Submit" />
</form>

- Kiran Makam
Sep 16 '08 #4
On Sep 15, 11:13*pm, Kiran Makam <kiranm...@gmai l.comwrote:
On Sep 16, 8:06*am, white lightning <crescent...@ya hoo.comwrote:
But when I removed the submit button from the <form>, the
this.form.submi t() works fine.

The name of your submit button is 'submit' which is overriding the
form's submit function. Rename the button to something else, it should
work fine:

<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post"
enctype="multip art/form-data" name="form1">
* <select onchange="this. form.submit();" name="prod">
* * * * <option value="">Select product</option>
* * * *<option value="12">abc</option>
* </select>

* <input type="submit" name="mySubmitB utton" value="Submit" />
</form>

- Kiran Makam
Good catch!

My bad, OP. 'this.form' just did not look right to me for some reason,
but apparently it is.

byw, what does 'this' refer to in this case? Certainly not the select
element?
Sep 16 '08 #5
Doug Gunnoe wrote:
On Sep 15, 11:13 pm, Kiran Makam <kiranm...@gmai l.comwrote:
>On Sep 16, 8:06 am, white lightning <crescent...@ya hoo.comwrote:
>>But when I removed the submit button from the <form>, the
this.form.sub mit() works fine.
The name of your submit button is 'submit' which is overriding the
form's submit function. Rename the button to something else, it should
work fine:

<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post"
enctype="multi part/form-data" name="form1">
<select onchange="this. form.submit();" name="prod">
<option value="">Select product</option>
<option value="12">abc</option>
</select>

<input type="submit" name="mySubmitB utton" value="Submit" />
</form>
[...]

[...]
byw, what does 'this' refer to in this case? Certainly not the select
element?
No, it refers to the element object representing the `select' element in the
DOM tree :) That object implements a `form' property, which is also defined
in W3C DOM Level 2 HTML:

<http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-94282980>

AFAIK, the value of this in event handler attribute values (double meaning)
is not defined in any public standard yet. I have yet to see a scriptable
UA where it does not work so, though. (The `body' element makes one known
exception to the rule, but that is considered a bug.)

We have already discussed this several times before.
(Double meaning again ;-))
HTH

PointedEars
--
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
-- from <http://www.vortex-webdesign.com/help/hidesource.htm>
Sep 16 '08 #6
Doug Gunnoe <do********@gma il.comwrites:
Good catch!

My bad, OP. 'this.form' just did not look right to me for some reason,
but apparently it is.
yes.
byw, what does 'this' refer to in this case? Certainly not the select
element?
of course it does. see HTMLSelectEleme nt (or any other form
"sub-element") in:

http://www.w3.org/TR/REC-DOM-Level-1...e-binding.html

--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
Sep 16 '08 #7
Joost Diepenmaat wrote:
Doug Gunnoe <do********@gma il.comwrites:
>byw, what does 'this' refer to in this case? Certainly not the select
element?

of course it does. see HTMLSelectEleme nt (or any other form
"sub-element") in:
"Form control" is the precise, concise, and well-understood term for what
you call 'form "sub-element"' here. However, the meaning of `this' in event
handler attribute values is by far not limited to form controls.
http://www.w3.org/TR/REC-DOM-Level-1...e-binding.html
You are referring to an obsolete Specification[1] here, though.
The current Specification is
<http://www.w3.org/TR/DOM-Level-2-HTML/ecma-script-binding.html>
PointedEars
___________
[1] See <http://www.w3.org/TR/DOM-Level-2-HTML/>, "Status of this document",
final paragraph
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f8************ *******@news.de mon.co.uk>
Sep 16 '08 #8
Thomas 'PointedEars' Lahn wrote:
Joost Diepenmaat wrote:
>Doug Gunnoe <do********@gma il.comwrites:
>>byw, what does 'this' refer to in this case? Certainly not the select
element?
of course it does. see HTMLSelectEleme nt (or any other form
"sub-element") in:

"Form control" is the precise, concise, and well-understood
Awesome job on that!

http://groups.google.com/group/comp....c838c7d7b0bde6

Glad you figured it out.

term for what
you call 'form "sub-element"' here. However, the meaning of `this' in event
handler attribute values is by far not limited to form controls.
Garrett
Sep 16 '08 #9
On Sep 16, 11:35*am, Thomas 'PointedEars' Lahn <PointedE...@we b.dewrote:
Doug Gunnoe wrote:
byw, what does 'this' refer to in this case? Certainly not the select
element?

No, it refers to the element object representing the `select' element in the
DOM tree :)
Would it be a better interpretation if the above sentence be framed as
"it refers to the instance of the implementation of the HTMLElement
interface which represents the 'select' element in the DOM tree"?
Sep 16 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
6557
by: M Smith | last post by:
I have a form I want to submit to itself. I want to be able to type in a list of numbers and submit the form and have that list show up on the same form under the text box I typed them into and the buttons. The problem is when I post a form to itself, the Enter key will not submit the form, it only clears the contents of the text box. The...
15
2539
by: JR | last post by:
Hi. I hope someone out there who is more versed with JavaScript than I can help me with the following annoying problem. Here's the problem. I have a form with the following layout: Column A Column B Column C data 4 radio buttons more data .... ... ...
1
2041
by: marco | last post by:
Hi, I have this problem : when I submit a Form with the usual <html:form name="myForm" action="/myAction" type="org.apache.struts.validator.DynaValidatorActionForm"> ...... <input type="submit" name="action" value="Soumettre"> .....
2
1477
by: Martin | last post by:
Hi, I want to use Imagebuttons () to submit a form, as following: <form ....> <Input name="buttonEdit" type=Image onclick="ActionHandle("2")> <Input name="buttonnew" type=Image onclick="ActionHandle("1")> </form> But when I click a button, the function ActionHandle is not call. I want to know, which button the user click, to open the...
4
5577
by: Dmitry Korolyov [MVP] | last post by:
When we use btnSubmit.Attributes = "javascript: this.disabled=true;" to make the button disabled and prevent users from clicking it again while form data still posting, there is no longer postback. I.e. the button does go disabled, but the form does not invoke submit() method. Of course, it does work fine without this property. Clues?
0
1196
by: Dan Sikorsky | last post by:
We're using Remote Scripting to update counters, or colors, displaying on a web page form at a fixed interval, and the form's submit button event handler is executed without clicking the button. I detected this by putting a breakpoint on the first line of the handler. Because of this, the database insert, resulting from the button click...
6
8585
by: millw0rm | last post by:
i got a form full of radio buttons appx. 60-70, depends on the page. Some times 60, sometimes 55.... After certain period of time, i want to disable or make readonly all the radio button inside the form except submit button. i have done the timing part, i hav setup a running clock which will trigger the event @ XX amount of time but i m...
26
3879
by: pepper.gabriela | last post by:
Hello, a stupid question but... page_A.php is a page with a form. The user inserts text in four fields, then he clicks a submit button. The data goes to page_B.php: this page controls the data submitted, then echoes a message. If there were problems with the submitted data the message says: "a problem occurred with your data. Click here to...
4
5498
by: j1dopeman | last post by:
Hi, I'd like to use a button to save and then submit a form. I can set the onlick of the button to mahButton_click or submit, but I can't figure out how to do both. It looks like c# can't call a form's submit. I've found how to post programatically, but I need to use the form's target attribute so that the response goes into another...
0
7619
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7682
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7984
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6290
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5515
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5228
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3663
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1230
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
954
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.