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
    fxr
    fxr is offline
    New to the CF scene
    Join Date
    Feb 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    updating a dropdown list after ajax enabled event

    ok i have some php code embedded in my html that populates a dropdown list with entries from a mysql.

    now i need to think how i am going to repopulate that list [i.e pretty much rerun that segment of php code to update the dropdown list] when an ajax enabled action occurs.

    i have the ajax sorted for other types of updates, but i cant think through the logic for how i am going to update that list after these other events happen. [the dropdown list options need to change after these updates occur]

    i am using the prototypejs library

    i will post relevant sections of code..

    Code:
    	
    
    <script type="text/javascript">
    	function sendRequestClose() {
    
    		new Ajax.Request("sendmailclose.php", {
    	        method: 'post',
    		postBody: "tradeID="+$F("tradeID")+"&closeprice="+$F("closeprice"),
    			  
    			 onLoading: showLoading, //have to add alert
    				 
    			 onSuccess: function(transport){
    			    var response = transport.responseText || "no response text";
    			    alert("Success! \n\n" + response);
    											    },
    			     
    		       onFailure: function(){ alert('NO EMAILS SENT - NO RESPONSE FROM SERVER') },
    												
    		      onComplete: hideLoading	}
    	
    							);
    											
    		}
    </script>
    ....
    
    <p>
    	CLOSE TRADE : 
    	<!-- PHP -->
    	<?php
    	// Make a MySQL Connection
    	mysql_connect("localhost", "ssss", "sssss")or die(mysql_error());
    	mysql_select_db("db")or die(mysql_error());		
    	$result = @mysql_query("SELECT ID,open_time,pair,open_price,LS FROM log_open");
    
    	print "<select name=\"tradeID\" id=\"tradeID\">";
    	while ($row = mysql_fetch_assoc($result)) {
    		$tradeID = $row['ID'];
    		$opentime = $row['open_time'];
    		$pair = $row['pair'];
    		$price = $row['open_price'];
    	        if ($pair == "eu") {$price = round($price,4);} else {$price = round($price,2);}
    		$LS = $row['LS'];
    		print "<option value=$tradeID id=$tradeID>$tradeID $LS $pair $price $opentime";}
    		print "</select>";
    		?>
    	price <input name="closeprice" id="closeprice" type="text" size ="7">
    
    	<input type="submit" value="CLOSE" name="submit" onClick="javascript: sendRequestClose();"> 
    </p>
    I need that dropdown list generated by the php to be recreated after the sendRequestClose javascript is called.

    Can anyone point me in the right direction please? i am a relative newbie at this and i am struggling to get a grasp of the logic what i have to do here.

    Thhnaks.
    Last edited by fxr; 02-04-2009 at 07:21 PM.

  • #2
    fxr
    fxr is offline
    New to the CF scene
    Join Date
    Feb 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i have worked on this overnight and worked out that using innerHTML was my avenue to success. ll post my code for anyone who may stumble on this or be interested.

    Relevant snippets of code.

    Code:
    <script type="text/javascript">
     function DLChange(newHTML){
    	 document.getElementById('tradeID').innerHTML = newHTML;
    		 }
     
     function sendRequestClose() {
     
    	   new Ajax.Request("sendmailclose.php", {
    			method: 'post',
    			postBody: "tradeID="+$F("tradeID")+"&closeprice="+$F("closeprice"),
    			   
    			onLoading: showLoading, //have to add alert
    				  
    			onSuccess: function(transport){
    					 var response = transport.responseText || "no response text";
    					 var responder=response.split("<!-- DL -->");
     
    					 alert("Success! \n\n" + responder[0]);
    					 DLChange(responder[1]);
     
    												 },
    				  
    			 onFailure: function(){ alert('NO EMAILS SENT - NO RESPONSE FROM SERVER') },
    												 
    			 onComplete: hideLoading	}
    	 
    							 );
    											 
    		 }
     </script>
     
     ....
     
     CLOSE TRADE : 
     <select name="tradeID" id="tradeID">
     <!-- PHP -->
    	  <?php
    	   include 'opentrades.php';
    	   ?>
    opentrades.php looks like this and is included at the bottom of my sendmailclose.php script.

    Code:
    <?php
    		// Make a MySQL Connection
    		mysql_connect("localhost", "ssss", "sssss")or die(mysql_error());
    		mysql_select_db("db")or die(mysql_error());		
    		$result = @mysql_query("SELECT ID,opentime,pair,openprice,LS FROM logopen");
    		 print "<!-- DL -->";
    		 while ($row = mysql_fetch_assoc($result)) {
    			$tradeID = $row['ID'];
    			$opentime = $row['open_time'];
    			$pair = $row['pair'];
    			$price = $row['open_price'];}
    			$LS = $row['LS'];
    			print "<option value=$tradeID id=$tradeID>$tradeID $LS $pair $price $opentime";}
    			print "</select>";
    			?>


  •  

    Posting Permissions

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