sunnypal Posted September 11, 2009 Share Posted September 11, 2009 Hello, We are working on a form that has bunch of list boxes that display gender, ethnicity, student type values, etc in each of the list boxes. After the form is submitted these list box values are stored in a different tables. I am now working on retrieving and displaying values that have been inserted. We are able to retrieve and display single values (such as text boxes) but we are stumped with list boxes. We need to retrieve all the values for each list boxes that we previously inserted and then display these values as selected(higlhlighted) in the list box. We are using a combination of AJAX, javascript and php (to retrieve the db values). Has any one worked on list box values and their retrievals from the database. Any help would be appreciated. thanks, Quote Link to comment Share on other sites More sharing options...
holiks Posted September 11, 2009 Share Posted September 11, 2009 Someone else may care to elaborate a bit more...but I think I remember a while ago doing something like looping through the result set instead of retrieving "just one" and building the list that way. If a value is tagged as "selected" then tack on "selected" in the generated select_list_html. And there you have it....selected too. HTH ...even a bit Quote Link to comment Share on other sites More sharing options...
sunnypal Posted September 11, 2009 Author Share Posted September 11, 2009 I am able to retrieve the values in the listbox. But this is the scenario when one wants to update a record. The form (details.php) is run by a unique code, when the code is typed in onblur event triggers a function: getMSSQLData('find_mssqldata.php?schName='+document.inventoryForm.schName.value) where schName is the code that is passed to the find_mssqldata.php, the find_mssqldata.php retrieves all the values for that code below: find_mssql_data.php: <?php $selected = mssql_select_db($myDB, $dbhandle) or die("Couldn't open database $myDB"); $schName=$_REQUEST['schName']; $query = "select DISTINCT ETH from SD_ETH WHERE ETH_DTL_CD = '$schName' AND ETH_SEQ_NBR = (SELECT MAX(I.ETH_SEQ_NBR) FROM SD_ETH I WHERE I. ETH_DTL_CD = '$schName')"; $result = mssql_query($query); //$row = array(); while ($row = mssql_fetch_array($result,MSSQL_BOTH)) { echo $row['ETH']; echo "|"; } //echo "Scholar detail transaction complete"; mssql_close($dbhandle); ?> Next, in the details.php I have AJAX function calls to retrieve the values returned by find_mssqldata.php function getXMLHTTP() { var xmlhttp=false; try{ xmlhttp=new XMLHttpRequest(); } catch(e) { try{ xmlhttp= new ActiveXObject("Microsoft.XMLHTTP"); } catch(e){ try{ xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e1){ xmlhttp=false; } } } return xmlhttp; } but this is where it doesnt assign as selected values that are returned by find_mssqldata.php Below I tried testing assigned the very first value (mySplitResult[0]) as selected value but it keeps looping. I need a way to store all returned values first and then assign them as selected values. function getMSSQLData(strURL) { alert ("test"); var req = getXMLHTTP(); if (req) { //function to be called when state is changed req.onreadystatechange = function() { //when state is completed i.e 4 if (req.readyState == 4) { // only if http status is "OK" if (req.status == 200) { //alert ("test2"); //document.getElementById('Sname').value=req.responseText; var mySplitResult = req.responseText.split("|"); //updated alert(mySplitResult[0]); if(mySplitResult[0] == undefined){ document.inventoryForm.schType.options[document.inventoryForm.criEth.selectedIndex].text=''; document.getElementById('criCountry').focus(); } else { alert("k"); var k=0; var index =-1; do { if (mySplitResult[0] == document.inventoryForm.criEth[k].value) { index = k; alert("index"); break; } k = k + 1; } while (k < 2);//document.inventoryForm.criEth.length); document.inventoryForm.criEth[index].selected=true; } document.inventoryForm.criEth[0].selected=true; } else { alert("There was a problem while using XMLHTTP:\n" + req.statusText); } } } req.open("GET", strURL, true); req.send(null); } } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.