Jump to content

ajax noob - drop-down list populated fom live database when adding rows to page


fj1200

Recommended Posts

I have this posted on the Javascript page but wonder if ajax is the solution.  I've been playing with it this morning but getting nowhere.

 

function insRow()
         {
         var mytable=document.getElementById("advicenote")
         for (var i=0; i<1; i++){ //add 3 new rows with content to the end of a table
         var newrow=advicenote.insertRow(-1) //add new row to end of table
         
         var newcell=newrow.insertCell(0) //insert new cell to row
         newcell.innerHTML='<SELECT name="JOBNAME"><?php
               while($nt=mssql_fetch_array($result3))
               {
               echo "<option value='".$SITE_ID.".".$nt['JOB_NAME'].".".$nt['JOB_DESCRIPTION'].".".$JOBTYPE."'>".$nt['JOB_DESCRIPTION']."</option>";
               } ?></select>';
         
         var newcell=newrow.insertCell(1) //insert new cell to row
         newcell.innerHTML='<input name=\"depot_edition">';
         var newcell=newrow.insertCell(2) //insert new cell to row
         newcell.innerHTML='<input name=\"copies_bundle\">';
         var newcell=newrow.insertCell(3) //insert new cell to row
         newcell.innerHTML='<input name=\"bundles_std\">';
         var newcell=newrow.insertCell(4) //insert new cell to row
         newcell.innerHTML='<input name=\"bundles_odds\">';
         var newcell=newrow.insertCell(5) //insert new cell to row
         newcell.innerHTML='<input name=\"pallet_count\">';
         }
         }
      </script>

 

The above code adds a row of input boxes to a page.  BUT - the first box is a drop-down list of running jobs that needs to be populated from the SQL Server production database at time of clicking the Add button.  Tried all sorts, but it's not working.  The query works fine though.  I'm a bit of a noob to JS and Ajax, so willing to learn.  Been reading Tutorials all morning. 

 

Any help gratefuly recieved,

Link to comment
Share on other sites

I have now got a working ajax drop-down, does everything I need EXCEPT - I can't get it to sit in the first cell.  Tried everything I can think of, tried loads of other people's ideas, just not working. 

 

			function printpage(){
			window.print(); }
			//-->


		function insRow()
		{

		var ajaxRequest;  // The variable that makes Ajax possible!
		var mytable=document.getElementById("advicenote")
		for (var i=0; i<1; i++){ //add 3 new rows with content to the end of a table
		var newrow=advicenote.insertRow(-1) //add new row to end of table

		ajaxRequest.open("GET","ajax-advicenote.php", true);
		ajaxRequest.send(null); 

		ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){

		var ajaxDisplay = document.getElementById('job');
		ajaxDisplay.innerHTML = ajaxRequest.responseText;
	}
}
ajaxRequest.open("GET","ajax-example.php", true);
ajaxRequest.send(null); 
}
			}
		var newcell=newrow.insertCell(0) //insert new cell to row
		newcell.innerHTML= ajaxRequest.responseText;

 

 

I'm at a bit of a loss as to know what to do.  Can I give the newcell an id so I can reference it and so get the ajax response into it?  My first time with  ajax so be nice.  Taken me all day pretty much to get this far!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.