473,403 Members | 2,366 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,403 software developers and data experts.

onchange event with ASP and Javascript

15
Im work on a form that will dynamicly display objects. The form is completed and working but am adding some features that will appear based on the user selection. I am unable to get the onchange event to work. When I make the selection in the drop down nothing happens. Any help would be great thanks.

Expand|Select|Wrap|Line Numbers
  1.  
  2. <script language="JavaScript">
  3.  
  4. function showHideContent( id, show )
  5. {
  6. var elem = document.getElementById( id );
  7. if ( elem ) 
  8. {
  9. if ( show ) 
  10. {
  11. elem.style.display = 'block';
  12. elem.style.visibility = 'visible';
  13. else
  14. {
  15. elem.style.display = 'none';
  16. elem.style.visibility = 'hidden';
  17. }
  18. }
  19.  
Once the user selects the choice I want it to check if it matchs. If it does then to make an object visible.

Expand|Select|Wrap|Line Numbers
  1.  
  2. function ModSelection( selection )
  3.  
  4. {
  5. if ( selection == "Split Case Pick" )
  6. {
  7. showHideContent( 'SCP1', true);
  8. }
  9. else
  10. showHideContent( 'SCP1', false);
  11. }
  12. }
  13.  
  14.  
  15. </script>
  16.  
  17.  
The selection the user will make there choice.

Expand|Select|Wrap|Line Numbers
  1.  
  2. <div id="Form1">
  3. <table width="80%" align="center">
  4. <tr>
  5. <td width="18%" align="center">
  6. <font face="Arial" size="2">
  7.  
  8. <label>From Department: </label>
  9.  
  10. <% Response.Write( "<select name=""FDepartment1"" onchange=""ModSelection(this.options[this.selectedIndex].value)"" tabindex=""3"">" )
  11.  
  12. For a = 0 To UBound( mySQLDepList, 2 )
  13.     For b = 0 To UBound( mySQLDepList, 1 )
  14.         Response.Write("<option value='" & mySQLDepList(b, a) & "'>" & mySQLDepList(b, a) & "</option>" & vbCr)
  15.         Next
  16. Next
  17.  
  18. Response.Write("</select>" ) %>
  19. </font>
  20. </td>
  21. </tr>
  22. </table>
  23. </div>
  24.  
  25.  
The choice that will become visible.

Expand|Select|Wrap|Line Numbers
  1. <div style="display:none" id="SCP1">
  2. <td><select name="SCPSelection">
  3. <option value="M Mod">M Mod</option>
  4. <option value="L Mod">L Mod</option>
  5. </select></td>
  6. </div>
  7.  

-John
Jan 12 '08 #1
8 2414
shweta123
692 Expert 512MB
Hi,

Please check that ,if any of your functions are getting called on onchange event?



Im work on a form that will dynamicly display objects. The form is completed and working but am adding some features that will appear based on the user selection. I am unable to get the onchange event to work. When I make the selection in the drop down nothing happens. Any help would be great thanks.

Expand|Select|Wrap|Line Numbers
  1.  
  2. <script language="JavaScript">
  3.  
  4. function showHideContent( id, show )
  5. {
  6. var elem = document.getElementById( id );
  7. if ( elem ) 
  8. {
  9. if ( show ) 
  10. {
  11. elem.style.display = 'block';
  12. elem.style.visibility = 'visible';
  13. else
  14. {
  15. elem.style.display = 'none';
  16. elem.style.visibility = 'hidden';
  17. }
  18. }
  19.  
Once the user selects the choice I want it to check if it matchs. If it does then to make an object visible.

Expand|Select|Wrap|Line Numbers
  1.  
  2. function ModSelection( selection )
  3.  
  4. {
  5. if ( selection == "Split Case Pick" )
  6. {
  7. showHideContent( 'SCP1', true);
  8. }
  9. else
  10. showHideContent( 'SCP1', false);
  11. }
  12. }
  13.  
  14.  
  15. </script>
  16.  
  17.  
The selection the user will make there choice.

Expand|Select|Wrap|Line Numbers
  1.  
  2. <div id="Form1">
  3. <table width="80%" align="center">
  4. <tr>
  5. <td width="18%" align="center">
  6. <font face="Arial" size="2">
  7.  
  8. <label>From Department: </label>
  9.  
  10. <% Response.Write( "<select name=""FDepartment1"" onchange=""ModSelection(this.options[this.selectedIndex].value)"" tabindex=""3"">" )
  11.  
  12. For a = 0 To UBound( mySQLDepList, 2 )
  13.     For b = 0 To UBound( mySQLDepList, 1 )
  14.         Response.Write("<option value='" & mySQLDepList(b, a) & "'>" & mySQLDepList(b, a) & "</option>" & vbCr)
  15.         Next
  16. Next
  17.  
  18. Response.Write("</select>" ) %>
  19. </font>
  20. </td>
  21. </tr>
  22. </table>
  23. </div>
  24.  
  25.  
The choice that will become visible.

Expand|Select|Wrap|Line Numbers
  1. <div style="display:none" id="SCP1">
  2. <td><select name="SCPSelection">
  3. <option value="M Mod">M Mod</option>
  4. <option value="L Mod">L Mod</option>
  5. </select></td>
  6. </div>
  7.  

-John
Jan 13 '08 #2
jrayjr
15
No theres not. The only onchange event I have is the one I am trying to add.
Jan 13 '08 #3
jrayjr
15
I was able to get it working but not the way I would like to. I made the change in the ModSelection function but I would like it to compare the text instead of the index number.

Expand|Select|Wrap|Line Numbers
  1. function ModSelection(  )
  2.  
  3. {
  4. if ( document.MainForm.FDepartment1.selectedIndex == 19 )
  5. {
  6. showHideContent( 'SCP1', true);
  7. }
  8. else
  9. {
  10. showHideContent( 'SCP1', false);
  11. }
  12. }
  13.  
  14. </script>
  15.  
Thanks,
-John
Jan 14 '08 #4
shweta123
692 Expert 512MB
Hi,

Please refer this link for how to call onChange event of dropdown box.

I was able to get it working but not the way I would like to. I made the change in the ModSelection function but I would like it to compare the text instead of the index number.

Expand|Select|Wrap|Line Numbers
  1. function ModSelection(  )
  2.  
  3. {
  4. if ( document.MainForm.FDepartment1.selectedIndex == 19 )
  5. {
  6. showHideContent( 'SCP1', true);
  7. }
  8. else
  9. {
  10. showHideContent( 'SCP1', false);
  11. }
  12. }
  13.  
  14. </script>
  15.  
Thanks,
-John
Jan 14 '08 #5
jrayjr
15
Thanks shweta123 for the help. I was able to figure it out. The link that you referenced was pretty much the same thing I already had except it was using a variable but it still call the index number of the drop down. I needed to compare the text in the drop down not the index value due to the index number would change frequently with the database constently being updated.

Expand|Select|Wrap|Line Numbers
  1. function ModSelection( )
  2. {
  3.      if ( document.MainForm.FDepartment1.options.value == "Split Case Pick" )
  4.      {
  5.           showHideContent( 'SCP1', true);
  6.      }
  7.      else
  8.      {
  9.           showHideContent( 'SCP1', false);
  10.      }
  11. }
  12.  
Plus made one change in the SELECT on the form.

Expand|Select|Wrap|Line Numbers
  1. <% Response.Write( "<select name=""FDepartment1"" onchange=""ModSelection(this.options[this.selectedIndex].text)"" tabindex=""3"">" )
  2.  

Thanks again,
John
Jan 14 '08 #6
jrayjr
15
I was also wondering if you could have more then one onchange event on the form? Say I have 2 Drop Downs and I would like to have both of them to have an onchange event to fire if a certain selection is made.



Thanks,
John
Jan 14 '08 #7
shweta123
692 Expert 512MB
Hi ,

Please refer the example below if you want to compare the text in the drop down instead of its index.

Expand|Select|Wrap|Line Numbers
  1.  
  2.   <html>
  3.  <head>
  4.  <script type="text/javascript">
  5. function favBrowser()
  6. {
  7. var mylist=document.getElementById("myList");
  8. document.getElementById("favorite").value=mylist.options[mylist.selectedIndex].text;
  9. }
  10. </script>
  11. </head>
  12.  
  13. <body>
  14. <form>
  15. Select your favorite browser:
  16. <select id="myList" onchange="favBrowser()">
  17.   <option>Internet Explorer</option>
  18.   <option>Netscape</option>
  19.   <option>Opera</option>
  20. </select>
  21. <p>Your favorite browser is: <input type="text" id="favorite" size="20"></p>
  22. </form>
  23. </body>
For your second question , what do you mean by having more than one onChange event ? You can have more than one function which can be called for diffrent dropdown boxes.

I was also wondering if you could have more then one onchange event on the form? Say I have 2 Drop Downs and I would like to have both of them to have an onchange event to fire if a certain selection is made.



Thanks,
John
Jan 15 '08 #8
jrayjr
15
Thanks for the help shweta123 I was able to get it worked out. As far as my last question disregard it. It was dumb. Anyways thanks again.

-John
Jan 16 '08 #9

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

Similar topics

10
by: R.G. Vervoort | last post by:
I am using a javafunction (onclick in select) in which i am calling a function in php (thats why i send this to both php and javascript newsgroups). in the onclick i call the function...
1
by: Covad | last post by:
Hi all, For some reason my change() function is only called when the page loads. I'd much rather it gets called when the select changes. Here's the code: window.onload = init; function...
1
by: dan baker | last post by:
I am pretty much a newbie with javascript, and would like to get a little clarification on what I can do with an onChange javascript event handler. I have a dynamic page I build with perl and...
2
by: Asit | last post by:
In JavaScripts checks for an onChange event against the value of the textbox at the time of the last onChange event. Since an onChange Event never fired after you changed the text first time ,...
4
by: Zeebra3 | last post by:
Here goes: I have a web form with several asp:dropdownlists, with which, when selection is changed I want to fire an event defined in some clientside js. The content of the clientside code is...
3
by: jab3 | last post by:
Hello. I"m new to this group, and to JavaScript in general, so please forgive me if I breach local etiquette. I'm trying to implement some client-side 'dynamic' validation on a form. I'm having...
5
by: subhodey | last post by:
Hello, I have a ColdFusion online application that has a page having 2 textboxes. Corresponding to these 2 textboxes I have a Custom tag in coldfusion where the textbox is defined by <input...
4
by: auslandt | last post by:
I have an HTML file that includes a JavaScript. I would like this JavaScript to be able to create an "onChange=<function>" attribute against the password element. Here is an example page of the...
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...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
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...
0
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,...
0
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...

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.