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

onChange issue with select dropdown

3
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_NAME.VALUE_NAME.
options[document.FRM_NAME.VALUE_NAME.selectedIndex].value
}
//-->
</script>

<form action="" method="post" name="FRM_NAME">
<select name="VALUE_NAME" 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(FRM001, VAL001);" and onChange="go(FRM002, 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 2145
acoder
16,027 Expert Mod 8TB
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
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 Expert Mod 4TB
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('FRM_NAME', 'SELECT_NAME');"[/HTML]
kind regards
Mar 14 '08 #4
acoder
16,027 Expert Mod 8TB
Yes, and put the ".html" back in the option values or append it in the function.
Mar 14 '08 #5
idj
3
Thanks Guys for all your help. It works now :-). KR idj
Mar 17 '08 #6
acoder
16,027 Expert Mod 8TB
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
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...
2
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,...
2
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...
10
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...
5
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...
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...
1
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...
21
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...
16
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...
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
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: 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
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...
0
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...
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
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...

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.