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

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?update_doc=1&doc_id=27&version=1&revi sion=0&no_sop=SOP1435">SOP1435
<OPTION
VALUE="/cgi-bin/doctrack.cgi?update_doc=1&doc_id=3&version=1&revis ion=0&no_sop=SOP2223">SOP2223
<OPTION
VALUE="/cgi-bin/doctrack.cgi?update_doc=1&doc_id=5&version=1&revis ion=0&no_sop=SOP2224">SOP2224
<OPTION
VALUE="/cgi-bin/doctrack.cgi?update_doc=1&doc_id=33&version=1&revi sion=0&no_sop=SOP2225">SOP2225
</SELECT></td>
</tr>
</table></form>
<BR>
<input type="button" value="Next -->"
onClick="document.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 2380
"yankee" <ne******@hotmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.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.html" 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.elements['myType'];
this.form.action = 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*****@agricoreunited.com>
comp.lang.javascript 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.elements['myType'];
this.form.action = 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
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
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...
2
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...
1
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...
0
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...
1
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...
7
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...
16
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...
4
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...
1
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...
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.