473,804 Members | 3,686 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

onChange issue with select dropdown

3 New Member
Hi, I'm using the following code to redirect to a new page with a select dropdown, which works fine:

[HTML]<script type="text/javascript">
<!--
function go(){
location=
document.FRM_NA ME.VALUE_NAME.
options[document.FRM_NA ME.VALUE_NAME.s electedIndex].value
}
//-->
</script>

<form action="" method="post" name="FRM_NAME" >
<select name="VALUE_NAM E" id="VALUE_NAME " onChange="go(); ">
<option value="001.html ">001</option>
<option value="002.html ">002</option>
<option value="003.html ">003</option>
</select>
</form>
[/HTML]
The problem is when I have multiple select dropdowns, I'd like to use the same function with vars for FRM_NAME & VALUE_NAME!

eg:

onChange="go(FR M001, VAL001);" and onChange="go(FR M002, VAL002);"

As a complete newbie to JS, I'd appreciate any help and apologise if this is very basic.

Thanks in advance.

KR idj
Mar 13 '08 #1
6 2175
acoder
16,027 Recognized Expert Moderator MVP
Welcome to TSDN and to JavaScript programming!

No need to apologise for basic questions.

Just use arguments for the function and use the forms and elements arrays:
Expand|Select|Wrap|Line Numbers
  1. function go(frm, sel) {
  2.   location.href = document.forms[frm].elements[sel].value;
  3. }
Mar 13 '08 #2
idj
3 New Member
Hi Acoder, thanks for the reply.

I get an error:

Error: 'document.forms[...].elements' is null or not an object

I've used your supplied JS and the following HTML:

Expand|Select|Wrap|Line Numbers
  1. <form action="" method="post" name="FRM_NAME">
  2. <select name="SELECT_NAME" id="SELECT_NAME" onChange="go(FRM_NAME, SELECT_NAME);">
  3. <option value="001">001</option>
  4. <option value="002">002</option>
  5. <option value="003">003</option>
  6. </select>
  7. </form>
Any thoughts?

KR ijd
Mar 14 '08 #3
gits
5,390 Recognized Expert Moderator Expert
hi ...

you have to pass the params as string values (actually in your code you pass variable-names that refer to undefined values in this case), so use the following:

[HTML]onChange="go('F RM_NAME', 'SELECT_NAME'); "[/HTML]
kind regards
Mar 14 '08 #4
acoder
16,027 Recognized Expert Moderator MVP
Yes, and put the ".html" back in the option values or append it in the function.
Mar 14 '08 #5
idj
3 New Member
Thanks Guys for all your help. It works now :-). KR idj
Mar 17 '08 #6
acoder
16,027 Recognized Expert Moderator MVP
You're welcome. Glad it's working. Post again anytime should you have any more questions.
Mar 17 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

1
5171
by: Michelle | last post by:
I have tried every variation of the "onchange" statement below without any actual reloading of the page. I am hoping that the PHP PRINT statement is constructed wrong, otherwise it is javaScript error an needs to be posted in the javaScript newsgroup. The FireFox javaScript Console reports the following message: Error: missing : in conditional expression Source Code: location.href=themes.php?scheme=(form.color_schemes.options.value)
2
4134
by: Phil Powell | last post by:
I have a form with two single-choice dropdowns. Upon doing an onChange event on either one of them, I want to check to see if the other dropdown has also been selected. How would I do that, considering that this.parent causes an error "null or not an object"? Thanx Phil
2
27399
by: Mark Durgee | last post by:
I have a "submit" button in a form that creates a record in my Filemaker database that works as it should. This is the HTML for it: <INPUT TYPE="SUBMIT" name="-New" VALUE="Add Record"> I have a drop down list on that same form that works fine, but I want it to perform the same submit action as above once a value is chosen. This is the HTML for it:
10
7661
by: Ryan McGeary | last post by:
In a <select> drop-down, the onchange event isn't called when scrolling through the dropdown using the mouse-wheel and when crossing over a new <optgroup>. Using the example below, notice how the onchange event isn't called when mouse wheel scrolling between A3 and B1, but it works properly when scrolling between A1 and A2. E.g. ------------------------------------------
5
3596
by: Cheddar | last post by:
I'm having trouble creating a very simple running total of a few drop down list. I have three seperate dropdown lists, I want the user to simply select some numbers and have the total of the selected numbers displayed. I'm not much of a programmer and this is really just a experiment. Can anyone help me out here. I know the code below doesnt work (no form tags etx0 but I thought the logic was fine?
4
6138
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.
1
1504
by: madhusudangosula | last post by:
I need onchange in javascript for two dropdown list.. I have two dropdown list 1.Activity Type 2.Category At present both are independent to each other... Now the thing is i need to map those two tables...and if i select one field in Activity type ..onchange function should have to work ...This is my requirement..
21
29835
by: Leena P | last post by:
i want to basically take some information for the product and let the user enter the the material required to make this product 1.first page test.php which takes product code and displays prodcut anme have used ajax to avoid refreshing of page this works fine 2.now i have created one row with checkbox|select box|text|text|text|text| where in the select box values are fetched from table here also i have used ajax for getting the m_name...
16
4971
by: tarunkhatri | last post by:
Hi. I have a javascript function to change the value of the cell on chnage event of a dropdown list.My code is workin but the problem is that the value of the cell is chaning but not respective to the selected dropdown list( as there are 15 dropdown list and 15 cells), but only on the 1st cell. So need some identification for each cell. Can anyone help me just refine my code. <script type="text/javascript"> function displaytaskid(ths) { ...
0
10335
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
10323
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
10082
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...
1
7621
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
6854
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5525
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5652
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4301
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
2
3821
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.