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

OnChange Code Not Working With Multiple Forms

I've posted this in at least 6 other forums with no responses. I am completely new to AJAX, so I got this code from another site and installed it for what I need. It works great if I have only one form on the page ... however, once I have multiple forms on the page, it stops working but it doesnt throw an error code, so I have no clue where to look. Any help would be appreciated!

Select Field Code:
Expand|Select|Wrap|Line Numbers
  1. onChange="showField(this.value, 'QQTrim')"
Ajax.js:
Expand|Select|Wrap|Line Numbers
  1. function GetXmlHttpObject() {
  2.     var xmlHttp=null;
  3.     try {
  4.         xmlHttp=new XMLHttpRequest();
  5.     }
  6.         catch (e) {
  7.             try {
  8.                 xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  9.             }
  10.         catch (e) {
  11.             xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  12.         }
  13.     }
  14.     return xmlHttp;
  15. }
  16.  
  17. function showField(str, id){
  18.     var url="inc/ajaxforms.php"
  19.     url=url+"?modField="+id
  20.     url=url+"&modString1="+str
  21.     url=url+"&sid="+Math.random()
  22.     xmlHttp=GetXmlHttpObject();
  23.     xmlHttp.onreadystatechange= function() {
  24.         if (xmlHttp.readyState==4)
  25.             if (xmlHttp.status==200)
  26.                 writeHTML(xmlHttp, id);
  27.     }
  28.     xmlHttp.open("GET",url,true);
  29.     xmlHttp.send(null);    
  30. }
  31.  
  32. function writeHTML(req, id) {
  33.     document.getElementById(id).innerHTML = req.responseText;
  34. }
Mar 7 '07 #1
9 2217
acoder
16,027 Expert Mod 8TB
Welcome to TSDN (The Scripts).

Do all your forms have the same id?

Show your form code.
Mar 7 '07 #2
I've posted this in at least 6 other forums with no responses. I am completely new to AJAX, so I got this code from another site and installed it for what I need. It works great if I have only one form on the page ... however, once I have multiple forms on the page, it stops working but it doesnt throw an error code, so I have no clue where to look. Any help would be appreciated!

Select Field Code:
Expand|Select|Wrap|Line Numbers
  1. onChange="showField(this.value, 'QQTrim')"
Ajax.js:
Expand|Select|Wrap|Line Numbers
  1. function GetXmlHttpObject() {
  2.     var xmlHttp=null;
  3.     try {
  4.         xmlHttp=new XMLHttpRequest();
  5.     }
  6.         catch (e) {
  7.             try {
  8.                 xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  9.             }
  10.         catch (e) {
  11.             xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  12.         }
  13.     }
  14.     return xmlHttp;
  15. }
  16.  
  17. function showField(str, id){
  18.     var url="inc/ajaxforms.php"
  19.     url=url+"?modField="+id
  20.     url=url+"&modString1="+str
  21.     url=url+"&sid="+Math.random()
  22.     xmlHttp=GetXmlHttpObject();
  23.     xmlHttp.onreadystatechange= function() {
  24.         if (xmlHttp.readyState==4)
  25.             if (xmlHttp.status==200)
  26.                 writeHTML(xmlHttp, id);
  27.     }
  28.     xmlHttp.open("GET",url,true);
  29.     xmlHttp.send(null);    
  30. }
  31.  
  32. function writeHTML(req, id) {
  33.     document.getElementById(id).innerHTML = req.responseText;
  34. }
================
I could not find anything wrong with your code.
But I assume you may have used same elements 'id' for all the element.
An element id must be unique throughout the document.
Mar 7 '07 #3
The ID is only used once throughout the entire page ... that was the first thing that I checked ...
Mar 7 '07 #4
Actually, if you want to check out the script in action ...

It works great here (Quick Quote Form on Left)
http://www.newyorkjeeps.com/

But stops working here
http://www.newyorkjeeps.com/jeep/new/
Mar 7 '07 #5
acoder
16,027 Expert Mod 8TB
I checked the page. The Ajax function is definitely being called, but it is failing. You can change your code to check the status.

I know this sounds daft, but since it is in a new directory, are you sure you have inc/ajaxforms.php in your jeep/new directory - in other words, does the file exist?
Mar 7 '07 #6
/jeep/new is actually redone by apache (.htaccess) to point to index.php?module=new. Everything on the site is driven by one page ... so it shouldnt be a problem or could I be wrong?
Mar 7 '07 #7
Thanks for the enlightenment! In the AJAX.js file, I changed the following:

var url="inc/ajaxforms.php"
url=url+"?modField="+id
url=url+"&modString1="+str
url=url+"&sid="+Math.random()

to:

var url="/inc/ajaxforms.php"
url=url+"?modField="+id
url=url+"&modString1="+str
url=url+"&sid="+Math.random()

Even though everything is generated off of one page, I guess because I am "faking" the directory structure, the "/" at the beginning was needed! Thanks for pointing that out for me!
Mar 7 '07 #8
acoder
16,027 Expert Mod 8TB
Seventh time lucky, eh?
Mar 8 '07 #9
I guess ... lol!
Mar 8 '07 #10

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

Similar topics

2
by: please-answer-here | last post by:
Scenario: I'm having an asp page with a form with an action pointing to itself. The reason for that, it that the asp page depending on changes in any of two select fields with data from 2...
8
by: Mattias Campe | last post by:
Hello, On http://student.ugent.be/astrid/bewoners.php I got the problem that I want Javascript to let my browser go to http://student.ugent.be/astrid/bewoners.php?beginAcjaar=2002 when I 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...
5
by: doc | last post by:
Hi, <SCRIPT LANGUAGE="JavaScript"> function check_selection(selection){ document.pr.n_o.checked=true; } </SCRIPT> <form name=pr action=test.php method=post>
5
by: Pascal Batzli Jr | last post by:
Hello, I have a strange situation happening on the code below. When I first load the page, as I change any of the three combo boxes I have created, the onchange event is fired and the form should...
4
by: Craig831 | last post by:
First off, I apologize if this gets long. I'm simply trying to give you all enough information to help me out. I'm writing (almost finished, actually), my first VB.Net application. It's a forms...
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...
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...
15
by: colyn7 | last post by:
I really can't see what's wrong in my code... the submit() onChange doesn't work.. I've tried.. <select name="ddlTestCenter" id="ddlTestCenter" style="width:180px"...
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...
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
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
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
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...
0
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...

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.