473,549 Members | 2,723 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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="myselec t">

<select name='myselect' size='1' onChange='MySel ectSubmit()'>
<option value='hi' selected='selec ted' >Hello</option>
<option value='bye'>Goo dbye</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 8664
On Mon, 19 Jan 2004 10:23:41 -0800, Jason Novotny <no*****@aei.mp g.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.******@blueyo nder.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="myselec t">

<select name='myselect' size='1' onChange='MySel ectSubmit()'>
<option value='hi' selected='selec ted' >Hello</option>
<option value='bye'>Goo dbye</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='MySel ectSubmit(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
2275
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 to dynamically select from this list and add to the first list. I also want the user to be able to dynamically remove from and reorder the first...
5
2456
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 loop through there and add each item to a table. I can add the other info fromt he form to a table, just not the otems in the listbox. It only shows...
1
2226
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 the list.
10
3450
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 answer why ? The impact of this is that values added via javascript will never make it back to the server side code unless one does some jiggery pokery...
1
2310
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' action=''> <select name='select'> <option value='A'>Item A</option> <option value='B'>Item B</option> <option value='C'>Item C</option> <option...
1
10778
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 have defined the relavant function method in the code for details) The issue is that when Icall targetForm._submit() method from the newSubmit()...
3
4944
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 to pages.The other form is the main component of the page. It has radiobuttons and textfields for the user to select/enter input. The links have...
14
75448
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" enctype="multipart/form-data" name="form1"> <select onchange="this.form.submit();" name="prod"> <option value="">Select product</option> <option value="12">abc</option>
13
10544
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 user clicks "yes" or "no". This Object is attached to various HTML elements on the page (buttons, selects etc) and traps any events that they...
0
7450
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...
0
7720
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7957
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7470
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
7809
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...
1
5368
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
3500
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...
0
3481
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1941
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.