Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Dec 2008
    Posts
    14
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Ajax-out of 3 forms, only last form element update

    I HAVE A 2 FORMS IN ONE PAGE. EACH FORM HAVING A SELECT ELEMENT NAME COL2, AM USING A FUNCATION CALLED getagentids() WHICH RETREIVE A DATA FROM MYSQL THROUGH PHP AND FILL THE SELECT ELEMENT. I WANT TO CALL THE FUNCTION AJAX CONTAINING FUNCTION getagentids() EVERY TIME WHEN THE PAGE LOAD OR WHEN ON CHANGE EVENT IN THE SAME COL2 SELECT ELEMENT. WHAT HAPPEN WAS FORM2 THAT IS "selectForm2" COL2 ONLY UPDATE. IF I ADD ONE MORE FORM, THE LAST FORM ONLY GETS UPDATED. OUT OF 2 FORMS THE SAME FUNCTION UPDATE ONLY ONE FORM SELECT ELEMENT. PLS GIVE ME SOME TIPS TO FIX THIS PROBLEM

    Code:
    <FORM NAME="selectForm1">
    	<SELECT NAME=COL2 style="WIDTH: 105px; BACKGROUND-COLOR: aqua" onchange="getagentids(this.form,'COL2');">
    		<OPTION selected VALUE="SELECT">SELECT</OPTION>
    		<OPTION VALUE="START" style="BACKGROUND-COLOR: lightgreen">START</OPTION>
    	</SELECT>
    </FORM>
    <FORM NAME="selectForm2">
    	<SELECT NAME=COL2 style="WIDTH: 105px; BACKGROUND-COLOR: aqua" onchange="getagentids(this.form,'COL2');">
    		<OPTION selected VALUE="SELECT">SELECT</OPTION>
    		<OPTION VALUE="START" style="BACKGROUND-COLOR: lightgreen">START</OPTION>
    	</SELECT>
    </FORM>

    Code:
            function getagentids(inform,cname)
            {
    	        
    	        resetteamstatus();
    	        formname = inform;
    	        colname = cname;
    
    		var idValue = 'load';
    		formname.COL2.options.length =1;
    		var myRandom=parseInt(Math.random()*99999999);  // cache buster
    		http.open("GET", urlxtp + escape(idValue) + "&rand=" + myRandom, true);
    		http.onreadystatechange = handleHttpResponse;
    		http.send(null);
    
            }

  • #2
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    Loose the caps, makes your post unreadble.

    You code is not Object Oriented. So if you call it two times in a row when the first post is active you write over all of your previous global variables.

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •