3 Replies - 3186 Views - Last Post: 14 February 2013 - 08:35 AM Rate Topic: -----

#1 darb93  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 16
  • Joined: 28-August 12

Populate a listbox from a database using php

Posted 14 February 2013 - 08:10 AM

Hi all, I am just wondering how would i populate my listbox in this code with results from my database.
<html>
<body>
<a href="home.php">Home</a>
<a href="insert.html">Add Staff Member</a>
<a href="display.php">Display Details</a>
<a href="displaytable.php">Show Staff Available</a> 
<a href="delete.html.php">Delete Staff Member</a> ;
<a href="AmendView.html.php">Amend Staff Member</a>


<h1> Delete a Person</h1>
<h4>Please select a person and then click the delete button</h4>

 
<br><select name = 'listbox' id = 'listbox' onclick = 'populate()'> </select>
<script>

function populate()
{
var sel = document.getElementById("listbox");
var result;
result = sel.options[sel.selectedIndex].value;
var personDetails = result.split(',');
document.getElementById("display").innerHTML = "The details of the selected person are: " + result;
document.getElementById("delid").value = personDetails[0];
document.getElementById("delfirstname").value = personDetails[1];
document.getElementById("dellastname").value = personDetails[2];
document.getElementById("delage").value = personDetails[3];
document.getElementById("delDOB").value = personDetails[4];
}



function confirmCheck()
{
var response;
response = confirm('Are you sure you want to delete this person?');
if (response == true)
{
document.getElementById("delid").disabled = false;
document.getElementById("delfirstname").disabled = false;
document.getElementById("dellastname").disabled = false;
document.getElementById("delage").disabled = false;
document.getElementById("delDOB").disabled = false;
}
else
{
alert("Cancel pressed");
}
return response;
}



 
</script>

<p id = "display"> </p>

<form action = "delete.html.php" method = "post" onsubmit = "return confirmCheck()">
<table cellspacing = "10">
<tr><td><label>Person Id </td> <td><input type = "text" name = "delid" id = "delid"  disabled> </label></td></tr>
<tr><td><label>First Name </td><td><input type = "text" name = "delfirstname" id = "delfirstname" disabled > </label></td></tr>
<tr><td><label>Surname</td> <td><input type="text" name = "dellastname" id = "dellastname" disabled> </label></td></tr>
<tr><td><label>Age </td><td><input type = "text" name = "delage" id = "delage"  disabled> </label></td></tr>
<tr><td><label>Date of Birth </td><td><input type = "text" name = "delDOB" id = "delDOB" title = "format is dd-mm-yyyy" disabled> </label></td></tr>

</table>
<input type = "submit" name = "submit" value = "Delete">
</form>

</body>
</html>



Is This A Good Question/Topic? 0
  • +

Replies To: Populate a listbox from a database using php

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3489
  • View blog
  • Posts: 10,055
  • Joined: 08-June 10

Re: Populate a listbox from a database using php

Posted 14 February 2013 - 08:15 AM

we have a nice little tutorial on that topic: http://www.dreaminco...ment-using-dom/

This post has been edited by Dormilich: 14 February 2013 - 08:15 AM

Was This Post Helpful? 0
  • +
  • -

#3 darb93  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 16
  • Joined: 28-August 12

Re: Populate a listbox from a database using php

Posted 14 February 2013 - 08:28 AM

Thanks for your reply but I am working with just PHP,Javascript,SQL,HTML and CSS. XML is not being used in this cause we have not covered it in college.
Was This Post Helpful? 0
  • +
  • -

#4 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3489
  • View blog
  • Posts: 10,055
  • Joined: 08-June 10

Re: Populate a listbox from a database using php

Posted 14 February 2013 - 08:35 AM

regard HTML as a special case of XML.

DOM, which you need for HTML-JS interaction, is a platform-independent API, so PHP-XML is hardly different from JS-HTML.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1