473,785 Members | 2,466 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using SELECT value with onClick event

Hi all,

I have the following HTML code:

<form>
<table border=1 cellspacing=0 cellpadding=3>
<tr>
<td>Select a Document:</td>
<td><SELECT name="type" id="type">
<OPTION
VALUE="/cgi-bin/doctrack.cgi?up date_doc=1&doc_ id=27&version=1 &revision=0&no_ sop=SOP1435">SO P1435
<OPTION
VALUE="/cgi-bin/doctrack.cgi?up date_doc=1&doc_ id=3&version=1& revision=0&no_s op=SOP2223">SOP 2223
<OPTION
VALUE="/cgi-bin/doctrack.cgi?up date_doc=1&doc_ id=5&version=1& revision=0&no_s op=SOP2224">SOP 2224
<OPTION
VALUE="/cgi-bin/doctrack.cgi?up date_doc=1&doc_ id=33&version=1 &revision=0&no_ sop=SOP2225">SO P2225
</SELECT></td>
</tr>
</table></form>
<BR>
<input type="button" value="Next -->"
onClick="docume nt.forms[0].type.submit(); ">

When I click on the button, I have a javascript error. I just want to
execute the command into the "VALUE" argument when I click on the
button. How I can do that?

Thank you

Regards,
Yanick Quirion

Jul 23 '05 #1
2 2404
"yankee" <ne******@hotma il.com> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.com.. .
When I click on the button, I have a javascript error. I just want to
execute the command into the "VALUE" argument when I click on the
button. How I can do that?
Give your <form> a default action:

<form action="noJS.ht ml" method="GET">

Change the name and id of your <select> to something other than "type"
(a Select object has a "type" property which you are overriding by
naming it that). Also the name and the id should not be the same:

<select name="myType" id="myTypeId">

Then have a submit button as follows:

<input type="submit"
value="Next -->"
onclick="
var s = this.form.eleme nts['myType'];
this.form.actio n = s.options[s.selectedIndex].value;
"


This way, if JavaScript is available, the -action- of the form will
change and the form will do a GET to the value of the currently selected
Optioin. If JavaScript is disabled or unavailable, the form will submit
to the default action you specified display a page telling the user the
form only works if they have JavaScript enabled.

--
Grant Wagner <gw*****@agrico reunited.com>
comp.lang.javas cript FAQ - http://jibbering.com/faq
Jul 23 '05 #2
Grant Wagner wrote:
[...]
... Also the name and the id should not be the same:

<select name="myType" id="myTypeId">
I thought id and name should be the same because of the way IE seems to
treat them as equals (in IE, getElementById( 'x') will get a named form
element named x even if it has no id, where as other browsers will only
get it if it has an id x).

Can you elaborate?

Then have a submit button as follows:

<input type="submit"
value="Next -->"
onclick="
var s = this.form.eleme nts['myType'];
this.form.actio n = s.options[s.selectedIndex].value;
"
Would this be better as an onsubmit on the form, rather than on onclick
on the submit button? To me that seems better from a maintenance point
of view, so the action, onsubmit, etc. are all coded in the same place
but there may be other issues to consider.

The OP has put the "submit" outside the form, will this.form... still
work? I think you are suggesting the submit be *in* the form, I'm not
sure the OP will realise that.

If the submit is to be triggered from outside the form, then that may
be an argument for including any actions in the form's onsubmit, rather
than on the button (though there are likely arguments both ways). I'd
be more curious as to why the submit is not in the form.
This way, if JavaScript is available, the -action- of the form will
change and the form will do a GET to the value of the currently selected
Optioin. If JavaScript is disabled or unavailable, the form will submit
to the default action you specified display a page telling the user the
form only works if they have JavaScript enabled.


Or do the required function on the server?
--
Rob
Jul 23 '05 #3

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

Similar topics

12
8884
by: Forti2ude | last post by:
Hello, I have a simple form... <form> <select name="foo" multiple> <option value="1">one</option> <option value="2">two</option> <option value="3">three</option> </select>
4
6137
by: Bart van Deenen | last post by:
Hi all I have a script where I dynamically create multiple inputs and selects from a script. The inputs and selects must have an associated onchange handler. I have the script working fine on Firefox, Safari and Konqueror, but the onchange event just doesn't fire on IE6. Firefox's javascript console shows no errors, and the IE script debugger shows nothing. onchange is not triggered.
2
1623
by: jascraig | last post by:
Here's my dilemma. I'm working with a frameset with 3 frames (header,content,control). My control frame contains a select list with buttons for next and previous. When the next button is pushed the select list moves to the next option and the content frame changes to the next URL, and a page number is updated on the header. The code I have now works great on NS 7 and FF1. When I test it in IE, the select box updates then immediately...
1
2766
by: smash2004 | last post by:
I want to keep selected values in select list when i click on another option...with a click on a mouse... if i have 3 options in select list and i click first option..it gets selected..if i then click on third option ..it gets selected but i want also the first option to stay selected when i click on option that is already selected, then it should be deselected
0
466
by: Tim | last post by:
Access 97: I have a table with a hyperlink field that I display on a form. I can click on the form field and the hyperlink activates correctly. However, if I try to activate the hyperlink using VB code, the last hyperlink that was clicked is the only one that displays. Background: The database is for providing instruction documentation for shop-floor personnel in a manufacturing environment. The main purpose of the database is to provide...
1
7342
by: puneet.bansal | last post by:
Hi, I want to know the index of the option that a user clicks on in a multiple-select object (regardless of whether he selected or deselected it). This seems fairly simple but I can't seem to figure out how to do it. Does anybody know how to do this? Thanks. Puneet
7
33692
by: prash.marne | last post by:
Hello, I have a simple form <form method="POST"> <select name="activity"> <option value="0">None</option> <option value="M" onclick="popup_onclick()">Select Multiple</option> <option value="1">Kayaking</option>
16
2748
by: Richard Maher | last post by:
Hi, I have this Applet-hosted Socket connection to my server and in an ONevent/function I am retrieving all these lovely rows from the server and inserting them into the Select-List. (The on screen appearance of the Select List grows for the first 5 rows then the scroll bar appears if there's more). So far so good. . . The problem is that none of the rows I'm inserting appear on the screen until I have RETURNed from my function; so If...
4
1742
by: James | last post by:
Hello everyone, While loading a page (http://www.edmonton.ca/portal/server.pt?space=CommunityPage&control=SetCommunity&CommunityID=239) into a webbrowser control I use invokemember on the 'onclick' event from 'cmdBusStopScheduleSubmit' element - see below. ONCLICK ========= <input type="submit" name="cmdBusStopScheduleSubmit" value="Get Bus Stop
1
3463
by: swethak | last post by:
hi, i have a code to disply the calendar and add events to that. It works fine.But my requirement is to i have to disply a weekly and daily calendar.Any body plz suggest that what modifications i have to made in my code <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type"...
0
9485
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10161
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10098
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
9958
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8986
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7506
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5523
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3662
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2890
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.