Jump to content

sunnypal

New Members
  • Posts

    8
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

sunnypal's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hello, I have a very similar issue , my script is only able to set the very first value as selected, if a listbox has multiple values that were previously inserted, it is only able to assign the first value as selected value. Below the outer while retrieves the listbox citizenship values from MS SQL database that were previously inserted and then,the inner while is for oracle (that is why you see oci call) that hits oracle table and retrieves all citizenship values and compares with that values that were inserted into the MS SQL database and tried to set them as selected but is sets only the first record as selected. Any help would be appreciated?? while ($msrow = mssql_fetch_array($result,MSSQL_BOTH)) { $CITZ = $msrow['CITZ']; while ($row = oci_fetch_assoc($stmt)) { $sel =((trim($msrow['CITZ']) == trim($row['CODE'])) ? 'selected' : NULL ); echo "<option value='". $row['CODE'] ."' '. $sel .'>". $row['DESC'] ."</option>"; } }
  2. I am trying to acheive similar selection but for a listbox, this code retrieve and assigns only one value as selected value for the drop down box, but how can this be extended to assign multiple values in the list box as selected values. I tried this but even though for the code 1000 there are two citizenship values of T and I, the code just assigns the last value (I) as selected value in the list box. the outer loop is for oracle database and in the inner (loop) calls are from MS SQL database. <?php //Oracle connection if ($c = oci_pconnect ('','', "")) { //echo "Successfully connected to Oracle.\n"; $stmt = oci_parse($c, "select stvcitz_code as CODE, stvcitz_code ||' - '||stvcitz_desc as \"DESC\" from stvcitz"); oci_execute($stmt, OCI_DEFAULT); echo "<select name=\"criCitz[]\" class=\"selectionval\" multiple=\"multiple\" size=\"4\" onblur=\"checkListCITZ(this.form)\" id =\"criCitz\">"; echo "<option value='')></option>"; // start of MS SQL connection $myServer = ""; $myUser = ""; $myPass = ""; $myDB = ""; $dbhandle = mssql_connect('','','') or die("Couldn't connect to SQL Server on $myServer"); $selected = mssql_select_db($myDB, $dbhandle) or die("Couldn't open database $myDB"); $query = "select DISTINCT CITZ from SD_CITZ WHERE CITZ_DTL_CD = '1000' AND CITZ_SEQ_NBR = (SELECT MAX(I.CITZ_SEQ_NBR) FROM SD_CITZ I WHERE I. CITZ_DTL_CD = '1000')"; $result = mssql_query($query); while ($msrow = mssql_fetch_array($result,MSSQL_BOTH)) { $CITZ = $msrow['CITZ']; while ($row = oci_fetch_assoc($stmt)) { $sel = ( trim($CITZ) == $row['CODE'] ) ? ( 'selected' ) : ( NULL ); echo "<option value='".$row['CODE']."' '. $sel .'>".$row['DESC']."</option>"; } } mssql_close($dbhandle); echo "</select>"; oci_close($c); } else { echo "Oracle Connect Error "; } ?> thanks for your help
  3. 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); } }
  4. 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,
  5. I got it to work, just a small change did it from document.inventoryForm.schDeptCode.options[document.inventoryForm.schDeptCode.selectedIndex].value=mySplitResult[6]; to document.inventoryForm.schDeptCode.options[document.inventoryForm.schDeptCode.selectedIndex].text=mySplitResult[6];
  6. I am able to retrieve all the values, however I am stuck with drop down box. below is the code that I have to assign the database value as the selected value in the dropdown box : var mySplitResult = req.responseText.split("|"); //updated if(mySplitResult[6] == undefined){ document.inventoryForm.schDeptCode.options[document.inventoryForm.schDeptCode.selectedIndex].value=''; } else { document.inventoryForm.schDeptCode.options[document.inventoryForm.schDeptCode.selectedIndex].value=mySplitResult[6]; } But for some reason it is now able to assign the value from the database as the selected value for the drop down. I put: alert(document.inventoryForm.schDeptCode.options[document.inventoryForm.schDeptCode.selectedIndex].value); and it does show the retrieved value correctly but just cant seem to assign it to the dropdown box as the selected value. However, the same code below works fine when it is a text box. Once I enter the fund code, it hits the database and retrieves the title and populates the text box with the fund title if(mySplitResult[0] == undefined){ document.getElementById('schTitle2').value=''; } else { document.getElementById('schTitle2').value=mySplitResult[0]; } Any help on the dropdown box? thanks,
  7. Thanks for pointing that out, I was a bit hasty but you were right. I just had to tweak it a little with oracle connectivity calls as our db is an oracle and not mysql but it all worked great. thanks
  8. Hi ncosgrove, I am trying something very similar to autopopulate form fields based on a fund code. I read you were able to solve this, would you mind sharing your code? Thanks in advance,
×
×
  • 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.