473,396 Members | 1,771 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,396 software developers and data experts.

select listbox that does a form submit


Hi,

I'm trying to create a listbox using <select> HTML tags that can do
a form submit when an option in the list is selected. So far this works,
function MySelectSubmit() {
document.myform.submit();
}

with HTML:

<form name="myform" method="post" action="myselect">

<select name='myselect' size='1' onChange='MySelectSubmit()'>
<option value='hi' selected='selected' >Hello</option>
<option value='bye'>Goodbye</option>
</select>

</form>

Now my question is how can I make the javascript method general enough
so I can pass in any form so that it does not have to refere to "myform"
in the body. I tried the following but it doesn't work:

function MySelectSeubmit( aform ) {
document.aform.submit();
}

Thanks, Jason

Jul 20 '05 #1
2 8645
On Mon, 19 Jan 2004 10:23:41 -0800, Jason Novotny <no*****@aei.mpg.de>
wrote:
I'm trying to create a listbox using <select> HTML tags that can do
a form submit when an option in the list is selected. So far this works,
I don't quite know the wisdom of that; it depends on the content of the
SELECT box and how clear it is that the selection made is final. What if
the user makes a mistake?
Now my question is how can I make the javascript method general enough
so I can pass in any form so that it does not have to refere to "myform"
in the body.


It depends what you are passing to the method. If it is a reference to the
form object, you can do:

function mySubmit( myForm ) {
myForm.submit();
}

If you are passing the name of the form, you'll need to do:

function mySubmit( myForm ) {
document.forms[ myForm ].submit();
}

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #2
Lee
Jason Novotny said:


Hi,

I'm trying to create a listbox using <select> HTML tags that can do
a form submit when an option in the list is selected. So far this works,
function MySelectSubmit() {
document.myform.submit();
}

with HTML:

<form name="myform" method="post" action="myselect">

<select name='myselect' size='1' onChange='MySelectSubmit()'>
<option value='hi' selected='selected' >Hello</option>
<option value='bye'>Goodbye</option>
</select>

</form>

Now my question is how can I make the javascript method general enough
so I can pass in any form so that it does not have to refere to "myform"
in the body. I tried the following but it doesn't work:

function MySelectSeubmit( aform ) {
document.aform.submit();
}


Only the first component of a dot-notation identifier may be a
variable. If aform is a variable containing the name of the
form, you can use:

document.forms[aform].submit();

but it would be even simpler to pass a reference to the form,
instead of its name. You would pass it with:

onChange='MySelectSubmit(this.form)'

Note that "this.form" is exactly what you would use. Don't
replace any part of it with your own names. It's a built-in
reference to the form that contains the form element that the
event handler belongs to.

Then your function would look like:

function MySelectSubmit( aform ) {
aform.submit();
}

Since "aform" is now a reference directly to the form, you
don't need to qualify it with the document reference.

Jul 20 '05 #3

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

Similar topics

1
by: Bruce | last post by:
On an HTML form, I have a select list that is fed dynamically with detail records when the master record is displayed on the form. There is also a second lookup list, and want to allow the user...
5
by: Melissa Cowan | last post by:
I am using Access 2000. I have the Developer's handbook and got the code for the mulit select listbox from there. It sends the selected value to another listbox, lstselected. What I need to do is...
1
by: sab | last post by:
Hi, We have a web form with a listbox. The listbox is a multiple select listbox and has data that looks something like: ALL Unit 1 Unit 2 Unit 3 Note: "ALL" is always the first item in...
10
by: Mr Newbie | last post by:
DropDown lists and Listboxes do not appear in the list of controls and values passed back to the server on PostBack in Request.Form object. Can someone confirm this to be correct and possibly...
1
by: kevin | last post by:
I was wondering using only javascript i am trying to figure this out. Lets say i have a drop down menu with the following items in it\ <form id='frmitems' name='frmitems' method='post'...
1
by: gbezas | last post by:
Hi All, I have added an event handler to redirect form.submit() to a newSubmit() method that I have defined (which does some additional processing before submitting the form). Additionally I...
3
by: annoula | last post by:
Hello, I'm sorry if this has come up before but I haven't been able to find a solution in any forum so far. I have a page with 2 forms. One form contains links that the user clicks to navigate...
14
by: white lightning | last post by:
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; ?>" method="post"...
13
Frinavale
by: Frinavale | last post by:
I've been trying all morning to cancel a form submit to the server. I have a JavaScript Object that determines whether or not the page should be submitted to the server depending on whether the...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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,...

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.