473,378 Members | 1,343 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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

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

I have something like this:

<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post"
enctype="multipart/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.submit() 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.submit() works fine.

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

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

I have something like this:

<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post"
enctype="multipart/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.submit() 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.submit() 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...@yahoo.comwrote:
But when I removed the submit button from the <form>, the
this.form.submit() 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="multipart/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="mySubmitButton" value="Submit" />
</form>

- Kiran Makam
Sep 16 '08 #4
On Sep 15, 11:13*pm, Kiran Makam <kiranm...@gmail.comwrote:
On Sep 16, 8:06*am, white lightning <crescent...@yahoo.comwrote:
But when I removed the submit button from the <form>, the
this.form.submit() 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="multipart/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="mySubmitButton" 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...@gmail.comwrote:
>On Sep 16, 8:06 am, white lightning <crescent...@yahoo.comwrote:
>>But when I removed the submit button from the <form>, the
this.form.submit() 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="multipart/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="mySubmitButton" 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********@gmail.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 HTMLSelectElement (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********@gmail.comwrites:
>byw, what does 'this' refer to in this case? Certainly not the select
element?

of course it does. see HTMLSelectElement (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.demon.co.uk>
Sep 16 '08 #8
Thomas 'PointedEars' Lahn wrote:
Joost Diepenmaat wrote:
>Doug Gunnoe <do********@gmail.comwrites:
>>byw, what does 'this' refer to in this case? Certainly not the select
element?
of course it does. see HTMLSelectElement (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...@web.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
On Sep 16, 6:17 pm, sasuke wrote:
>On Sep 16, 11:35 am, Thomas 'PointedEars' Lahn wrote:
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"?
Saying "instance of the implementation of the HTMLElement interface"
would seem wrong. Objects would not be implementations of interfaces,
but rather implement interfaces. Remember that this object (if
sufficiently standard) would also implement the Node, Element and
HTMLSelectElement interfaces.
Sep 16 '08 #11
Thomas 'PointedEars' Lahn <Po*********@web.dewrites:
Joost Diepenmaat wrote:
>Doug Gunnoe <do********@gmail.comwrites:
>>byw, what does 'this' refer to in this case? Certainly not the select
element?

of course it does. see HTMLSelectElement (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.
Ah right. Thanks.
However, the meaning of `this' in event handler attribute values is by
far not limited to form controls.
I know that, I was just pointing out the spec where it's specified that
those form controls all have a form property, reflecting the containing
form.

--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
Sep 16 '08 #12
[Quoting repaired]

sasuke wrote:
On Sep 16, 11:35 am, Thomas 'PointedEars' Lahn <PointedE...@web.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"?
No, because the (C++/Java) class of which the (C++/Java) element object is
an instance would implement several (DOM) interfaces. In fact, ISTM we are
usually dealing with two interacting application layers here: a (C++/Java)
class that implements one or more (DOM) interfaces, and instances thereof;
and corresponding ECMAScript host objects that provide restricted access to
those instances (and in some implementations also to the [C++/Java] class
in a certain way and to a certain extent) from within the ECMAScript
implementation.

But it would appear that your smiley detector is borken.
PointedEars
Sep 16 '08 #13
On Sep 16, 2:13*pm, Kiran Makam <kiranm...@gmail.comwrote:
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="multipart/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="mySubmitButton" value="Submit" />
</form>
THAT WORKS! THANKS FOR THE EXPLANATION!

Sep 17 '08 #14
On Sep 16, 1:00*pm, Joost Diepenmaat <jo...@zeekat.nlwrote:
I know that, I was just pointing out the spec where it's specified that
those form controls all have a form property, reflecting the containing
form.
Thanks to Thomas, Joost, and the others who answered. It makes perfect
sense now.

The above snip is where I was confused.
Sep 17 '08 #15

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

Similar topics

15
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...
15
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...
1
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...
2
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 ...
4
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...
0
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...
6
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...
26
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...
4
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.