473,395 Members | 2,798 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.

The onchange event in Ajax

Hi everyone, I need your help.

I used the onchange event in select:
Expand|Select|Wrap|Line Numbers
  1. <select name="menu" 
  2. onchange="window.location.href='?code='+this.options[this.selectedIndex].value;">
  3. <option value="code1">Testo 1</option>
  4.  

After loading I can read the value parameter code and show / hide items in relation to that value.

Now I upgraded to AJAX and I find this situation:
Expand|Select|Wrap|Line Numbers
  1. <select name="code" id="code" onChange="cerca_province();">
  2. <option value="code1">Testo 1</option>
  3.  
Expand|Select|Wrap|Line Numbers
  1. function cerca_province() 
  2. {
  3.  
  4. code=document.form.code.options[document.form.code.selectedIndex].value
  5.  
  6.     if (window.XMLHttpRequest) {
  7.         estrai_province= new XMLHttpRequest();
  8.         estrai_province.onreadystatechange = ricevi_province;
  9.         estrai_province.open("GET", "estrai.asp?code="+code, true);
  10.         estrai_province.send(null);
  11.  
  12.     } else if (window.ActiveXObject) {
  13.         estrai_province= new ActiveXObject("Microsoft.XMLHTTP");
  14.         if (estrai_province) {
  15.             estrai_province.onreadystatechange = ricevi_province;
  16.             estrai_province.open("GET", "estrai.asp?code="+code, true);
  17.             estrai_province.send();
  18.  
  19.         }
  20.     }
  21. }
  22.  
  23.  
  24.   function ricevi_province() {   
  25.     var province;       
  26.       if (estrai_province.readyState == 4) {        
  27.           province=estrai_province.responseText;
  28.  
  29.             document.getElementById('provincia').innerHTML = province;
  30.              }
  31.     }
  32.  
  33.  

But this way I can not read the value of parameter code and show / hide items in relation to that value.


Can you help me? Can someone help me?
Thanks in advance.
Nov 30 '10 #1
11 4833
I try this but not working:

Expand|Select|Wrap|Line Numbers
  1. <select name="codice" id="codice" onChange="cerca_province(this.value);">
  2. <option value="codice1">Testo 1</option>
  3.  
Dec 1 '10 #2
Dormilich
8,658 Expert Mod 8TB
to use cerca_province(this.value); you have to define a parameter in the function definition:
Expand|Select|Wrap|Line Numbers
  1. function cerca_province(val)
  2. { /* your function code */ }
PS. and of course you have to use the defined parameter.

PPS. with proper event handling, you could get the select’s value without further ado through this.value anywhere in the function.
Dec 1 '10 #3
Thanks for your suggestion, but not working...

In the asp page estrai.asp the value of parameter "codice" is correct but in the this asp page (index.asp) I don't not read the value of parameter "codice".

I don't receive error... but not read the value of parameter...

Can someone help me?

index.asp
Expand|Select|Wrap|Line Numbers
  1. <html>
  2.  
  3. <head>
  4. <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
  5. <script type="text/javascript" language="javascript">
  6.  
  7. var estrai_province;
  8. var codice
  9.  
  10. function cerca_province(codice) 
  11. {
  12.     if (window.XMLHttpRequest)
  13.     {
  14.         estrai_province = new XMLHttpRequest();
  15.     }
  16.     else if (window.ActiveXObject)
  17.     {
  18.         estrai_province = new ActiveXObject("Microsoft.XMLHTTP");
  19.     }
  20.  
  21.     if (estrai_province)
  22.     {
  23.         estrai_province.onreadystatechange = ricevi_province;
  24.         estrai_province.open("GET", "estrai.asp?codice="+codice, true);
  25.         estrai_province.send(null);
  26.     }
  27. }
  28.  
  29.   function ricevi_province() {   
  30.     var province;       
  31.       if (estrai_province.readyState == 4) {        
  32.           province=estrai_province.responseText;
  33.  
  34.             document.getElementById('provincia').innerHTML = province;
  35.              }
  36.  
  37.     }
  38.  
  39. </script>
  40. </head>
  41.  
  42.  
  43. <body>
  44. <form method="post" action="" name="form">
  45. <table>
  46.  
  47. <%nome_form="form"%>
  48.  
  49. <tr>
  50. <td>
  51. <select name="codice" onChange="cerca_province(this.options[this.selectedIndex].value);">
  52. <option value="0">Seleziona</option>
  53. <option value="1">1</option>
  54. <option value="2">2</option>
  55. <option value="3">3</option>
  56. <option value="4">4</option>
  57. </select>
  58. </td>
  59. </tr>
  60.  
  61. <tr>
  62. <td id="provincia"></td>
  63. </tr>
  64.  
  65. </table>   
  66.  
  67. //// This value not read ////                    
  68. <% response.write request.querystring("codice") & "<br>" %>
  69.  
  70. </form>
  71.  
  72. </body>
  73.  
  74. </html> 
  75.  
Dec 1 '10 #4
Dormilich
8,658 Expert Mod 8TB
Thanks for your suggestion, but not working...
not the way you think …

given the way AJAX works, why should line #68 return something at all?


one correction to make: remove var codice, codice is a parameter, not a variable.
Dec 1 '10 #5
OK, I correct the code.

Link of the page: http://www.romatitlan.com/public/index.asp

I need read the value of parameter "codice" also on the page index.asp.

It's possible?
Thanks.
Dec 1 '10 #6
you can do?
Dec 2 '10 #7
Dormilich
8,658 Expert Mod 8TB
given your link, the AJAX works without fail.
Dec 2 '10 #8
Yes, I have modify the script and I read the value of codice in the index.asp

But if I use the codice_value in the server language, for example in ASP query:

Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM tbl WHERE codice_value = ???
  2.  
What value should I write in this query?
Dec 2 '10 #9
Dormilich
8,658 Expert Mod 8TB
er, I didn’t understand that question.
Dec 2 '10 #10
I need execute ASP query using the value of variable "codice".

I read in the index.asp the value of variable "codice" with:

Expand|Select|Wrap|Line Numbers
  1. <span id="codice_value"></span>
  2.  
how do I change this ASP query ? :

Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM tbl WHERE codice_value = ??? 
  2.  
Thanks for your attention.
Dec 2 '10 #11
Dormilich
8,658 Expert Mod 8TB
sorry, but I can’t help you with ASP related questions.
Dec 2 '10 #12

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

Similar topics

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...
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...
3
by: b_naick | last post by:
I realize that the onChange event for a drop down can be trapped as follows: <select name="myDropDown" onChange="somefunc"> Is it possible to trap the onChange event outside of the select...
4
by: David McNerney | last post by:
Would anyone be able to tell me why I get an error in FireFox 1.5.0.1 for MacOSX when I type some text and hit Enter in the following form: <html> <body> <form action="http://example.com"...
3
by: itp | last post by:
I have moved to Matt Kruse's Javascript Toolbox. It has some great examples to get you going quickly! Unfortunately all the examples are based on a form/submit model. I would like to try using...
1
by: langdale | last post by:
I am using a popup calendar to populate an input field. When the contents of this field change I need the onChange event to fire so that I can perform further updates. The onChange event...
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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...
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,...

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.