Current location: Hot Scripts Forums » Programming Languages » PHP » help with multiple select used with php and mysql


help with multiple select used with php and mysql

Reply
  #1 (permalink)  
Old 10-08-04, 01:03 PM
isaacmlee isaacmlee is offline
New Member
 
Join Date: Oct 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
help with multiple select used with php and mysql

Hello gurus!!
I am trying to use javascript menu popup box to work with php. Php does not recognize an array without [] after the name of a field. But when I use [] after the name, the source code for javascript menu popup box does not work... Is there anyway to get around that problem?
For instance, I want to use <select size=5 name=parentList multiple>
</select> instead of <select size=5 name=parentList[] multiple>
</select> in the source code below.
thanx in advance!!!!

attached: javascript for popup multiple select menu

<!-- THREE STEPS TO INSTALL ITEMS POPUP LIST:

1. Paste the first code into a new file, save it as: modify.html
2. Copy the coding into the HEAD of your HTML document
3. Add the last code into the BODY of your HTML document -->

<!-- STEP ONE: Paste the first code into a new file, save it as: modify.html -->

<html>
<head>
<script language="JavaScript">
Begin
<!--
// Add the selected items in the parent by calling method of parent
function addSelectedItemsToParent() {
self.opener.addToParentList(window.document.forms[0].destList);
window.close();
}
// Fill the selcted item list with the items already present in parent.
function fillInitialDestList() {
var destList = window.document.forms[0].destList;
var srcList = self.opener.window.document.forms[0].parentList;
for (var count = destList.options.length - 1; count >= 0; count--) {
destList.options[count] = null;
}
for(var i = 0; i < srcList.options.length; i++) {
if (srcList.options[i] != null)
destList.options[i] = new Option(srcList.options[i].text, srcList.options[i].value);
}
}
// Add the selected items from the source to destination list
function addSrcToDestList() {
destList = window.document.forms[0].destList;
srcList = window.document.forms[0].srcList;
var len = destList.length;
for(var i = 0; i < srcList.length; i++) {
if ((srcList.options[i] != null) && (srcList.options[i].selected)) {
//Check if this value already exist in the destList or not
//if not then add it otherwise do not add it.
var found = false;
for(var count = 0; count < len; count++) {
if (destList.options[count] != null) {
if (srcList.options[i].text == destList.options[count].text) {
found = true;
break;
}
}
}
if (found != true) {
destList.options[len] = new Option(srcList.options[i].text, srcList.options[i].value);
len++;
}
}
}
}
// Deletes from the destination list.
function deleteFromDestList() {
var destList = window.document.forms[0].destList;
var len = destList.options.length;
for(var i = (len-1); i >= 0; i--) {
if ((destList.options[i] != null) && (destList.options[i].selected == true)) {
destList.options[i] = null;
}
}
}
// End -->
</SCRIPT>
</head>
<body onLoad="javascript:fillInitialDestList();">
<center>
<form method="POST">
<table bgcolor="#FFFFCC">
<tr>
<td bgcolor="#FFFFCC" width="74">Available</td>
<td bgcolor="#FFFFCC"> </td>
<td bgcolor="#FFFFCC" width="69">Selected</td>
</tr>
<tr>
<td bgcolor="#FFFFCC" width="85">
<select size="6" name="srcList" multiple>
<option value="1">Item 1
<option value="2">Item 2
<option value="3">Item 3
<option value="4">Item 4
<option value="5">Item 5
<option value="6">Item 6
</select>
</td>
<td bgcolor="#FFFFCC" width="74" align="center">
<input type="button" value=" >> " onClick="javascript:addSrcToDestList()">
<br><br>
<input type="button" value=" << " onclick="javascript:deleteFromDestList();">
</td>
<td bgcolor="#FFFFCC" width="69">
<select size="6" name="destList" multiple>
</select>
</td>
</tr>
<tr>
<td colspan=3 align="center">
<input type="button" value="Done" onClick = "javascript:addSelectedItemsToParent()">
</td>
</tr>
</table>
</form>
</body>
</html>

<!-- STEP TWO: Paste this code into the HEAD of your HTML document -->

<HEAD>

<SCRIPT LANGUAGE="JavaScript">
<!-- Original: Pankaj Mittal (pankajm@writeme.com) -->
<!-- Web Site: http://www.fortunecity.com/lavendar/lavender/21 -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
function small_window(myurl) {
var newWindow;
var props = 'scrollBars=yes,resizable=yes,toolbar=no,menubar=n o,location=no,directories=no,width=300,height=200' ;
newWindow = window.open(myurl, "Add_from_Src_to_Dest", props);
}
// Adds the list of selected items selected in the child
// window to its list. It is called by child window to do so.
function addToParentList(sourceList) {
destinationList = window.document.forms[0].parentList;
for(var count = destinationList.options.length - 1; count >= 0; count--) {
destinationList.options[count] = null;
}
for(var i = 0; i < sourceList.options.length; i++) {
if (sourceList.options[i] != null)
destinationList.options[i] = new Option(sourceList.options[i].text, sourceList.options[i].value );
}
for(var i = 0; i < destinationList.options.length; i++) {
if (destinationList.options[i] != null)
destinationList.options[i].selected = true;
}
}
// Deletes the selected items of supplied list.
function deleteSelectedItemsFromList(sourceList) {
var maxCnt = sourceList.options.length;
for(var i = maxCnt - 1; i >= 0; i--) {
if ((sourceList.options[i] != null) && (sourceList.options[i].selected == true)) {
sourceList.options[i] = null;
}
}
}

// End -->
</script>
</HEAD>

<!-- STEP TWO: Copy this code into the BODY of your HTML document -->

<BODY>

<center>
<form method=post>
<table border=1 bgcolor="#ffffcc">
<tr>
<td>
<select size=5 name=parentList multiple>
</select>
</td>
</tr>
<tr>
<td align=center>
<input type=button value="Add Item" onclick = "javascript:small_window('modify.html');">
</td>
<tr>
<td align=center>
<input type=submit value=submit onclick = "javascript:deleteSelectedItemsFromList(parentList ) ;">
</td>
</tr>
</table>
</form>
</center>

<p><center>
<font face="arial, helvetica" size="-2">Free JavaScripts provided<br>
by <a href="http://javascriptsource.com">The JavaScript Source</a></font>
</center><p>

<!-- Script Size: 5.27 KB -->
Reply With Quote
  #2 (permalink)  
Old 10-12-04, 03:22 AM
marklar's Avatar
marklar marklar is offline
Newbie Coder
 
Join Date: May 2004
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
You can do it, but like this:
document.form.elements['srcList[]']

I'll assume your Javascript is OK I haven't gone through it, but I did notice that you need to close your <option> tags.

This script shows how to do what you want:
<?php
if(isset($HTTP_POST_VARS['srcList'])){
foreach($HTTP_POST_VARS['srcList'] as $value){
echo $value . "<br />";
};
};
?>
<html>
<head>
<title>Multiple Select</title>
<script language="JavaScript">
<!--
function SelectAll(selectBox)
{
for (var i=0;i<selectBox.options.length;i++)
{
selectBox.options[i].selected=true;
}
}
//-->
</script></head>
<body>
<form name="myForm" method="POST" action="">
<select size="3" name="srcList[]" multiple>
<option value="1">Item 1</option>
<option value="2">Item 2</option>
<option value="3">Item 3</option>
</select>
<input type="submit" name="Submit" value="Submit">
<input type="button" name="submit1" value="Select ALL" onclick="SelectAll(document.myForm.elements['srcList[]'])">
</form>
</body>
</html>
Reply With Quote
  #3 (permalink)  
Old 10-15-04, 01:34 PM
isaacmlee isaacmlee is offline
New Member
 
Join Date: Oct 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
thanks Marklar!!! I attached a working javascript.

Thanks Marklar
You pulled out my rotten tooth. Everything now works wonderfully. I made some modification to the previous javascript to make it work and posted it here for others to use.
<!-- THREE STEPS TO INSTALL ITEMS POPUP LIST:

1. Paste the first code into a new file, save it as: modify.html
2. Copy the coding into the HEAD of your HTML document
3. Add the last code into the BODY of your HTML document -->

<!-- STEP ONE: Paste the first code into a new file, save it as: modify.html -->

<html>
<head>
<script language="JavaScript">
Begin
<!--
// Add the selected items in the parent by calling method of parent
function addSelectedItemsToParent() {
self.opener.addToParentList(window.document.forms[0].destList);
window.close();
}
// Fill the selcted item list with the items already present in parent.
function fillInitialDestList() {
var destList = window.document.forms[0].destList;
var srcList = self.opener.window.document.forms[0].elements[‘parentList[]’];
for (var count = destList.options.length - 1; count >= 0; count--) {
destList.options[count] = null;
}
for(var i = 0; i < srcList.options.length; i++) {
if (srcList.options[i] != null)
destList.options[i] = new Option(srcList.options[i].text, srcList.options[i].value);
}
}
// Add the selected items from the source to destination list
function addSrcToDestList() {
destList = window.document.forms[0].destList;
srcList = window.document.forms[0].srcList;
var len = destList.length;
for(var i = 0; i < srcList.length; i++) {
if ((srcList.options[i] != null) && (srcList.options[i].selected)) {
//Check if this value already exist in the destList or not
//if not then add it otherwise do not add it.
var found = false;
for(var count = 0; count < len; count++) {
if (destList.options[count] != null) {
if (srcList.options[i].text == destList.options[count].text) {
found = true;
break;
}
}
}
if (found != true) {
destList.options[len] = new Option(srcList.options[i].text, srcList.options[i].value);
len++;
}
}
}
}
// Deletes from the destination list.
function deleteFromDestList() {
var destList = window.document.forms[0].destList;
var len = destList.options.length;
for(var i = (len-1); i >= 0; i--) {
if ((destList.options[i] != null) && (destList.options[i].selected == true)) {
destList.options[i] = null;
}
}
}
// End -->
</SCRIPT>
</head>
<body onLoad="javascript:fillInitialDestList();">
<center>
<form method="POST">
<table bgcolor="#FFFFCC">
<tr>
<td bgcolor="#FFFFCC" width="74">Available</td>
<td bgcolor="#FFFFCC"> </td>
<td bgcolor="#FFFFCC" width="69">Selected</td>
</tr>
<tr>
<td bgcolor="#FFFFCC" width="85">
<select size="6" name="srcList" multiple>
<option value="1">Item 1
<option value="2">Item 2
<option value="3">Item 3
<option value="4">Item 4
<option value="5">Item 5
<option value="6">Item 6
</select>
</td>
<td bgcolor="#FFFFCC" width="74" align="center">
<input type="button" value=" >> " onClick="javascript:addSrcToDestList()">
<br><br>
<input type="button" value=" << " onclick="javascript:deleteFromDestList();">
</td>
<td bgcolor="#FFFFCC" width="69">
<select size="6" name="destList" multiple>
</select>
</td>
</tr>
<tr>
<td colspan=3 align="center">
<input type="button" value="Done" onClick = "javascript:addSelectedItemsToParent()">
</td>
</tr>
</table>
</form>
</body>
</html>

<!-- STEP TWO: Paste this code into the HEAD of your HTML document -->

<HEAD>

<SCRIPT LANGUAGE="JavaScript">
<!-- Original: Pankaj Mittal (pankajm@writeme.com) -->
<!-- Web Site: http://www.fortunecity.com/lavendar/lavender/21 -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
function small_window(myurl) {
var newWindow;
var props = 'scrollBars=yes,resizable=yes,toolbar=no,menubar=n o,location=no,directories=no,width=300,height=200' ;
newWindow = window.open(myurl, "Add_from_Src_to_Dest", props);
}
// Adds the list of selected items selected in the child
// window to its list. It is called by child window to do so.
function addToParentList(sourceList) {
destinationList = window.document.forms[0].elements[‘parentList[]’];
for(var count = destinationList.options.length - 1; count >= 0; count--) {
destinationList.options[count] = null;
}
for(var i = 0; i < sourceList.options.length; i++) {
if (sourceList.options[i] != null)
destinationList.options[i] = new Option(sourceList.options[i].text, sourceList.options[i].value );
}
for(var i = 0; i < destinationList.options.length; i++) {
if (destinationList.options[i] != null)
destinationList.options[i].selected = true;
}
}
// Deletes the selected items of supplied list.
function deleteSelectedItemsFromList(sourceList) {
var maxCnt = sourceList.options.length;
for(var i = maxCnt - 1; i >= 0; i--) {
if ((sourceList.options[i] != null) && (sourceList.options[i].selected == true)) {
sourceList.options[i] = null;
}
}
}

// End -->
</script>
</HEAD>

<!-- STEP TWO: Copy this code into the BODY of your HTML document -->

<BODY>

<center>
<form method=post>
<table border=1 bgcolor="#ffffcc">
<tr>
<td>
<select size=5 name=parentList[] multiple>
</select>
</td>
</tr>
<tr>
<td align=center>
<input type=button value="Add Item" onclick = "javascript:small_window('modify.html');">
<input type=button value="Delete Item" onclick = "javascript:small_window('modify.html');">
</td>
<tr>
<td align=center>
<input name=submit type=submit value=submit >
<input name=reset type=reset value=reset onclick = "javascript:deleteSelectedItemsFromList(elemen ts[‘parentList[]’]);">
</td>
</tr>
</table>
</form>
</center>

<p><center>
<font face="arial, helvetica" size="-2">Free JavaScripts provided<br>
by <a href="http://javascriptsource.com">The JavaScript Source</a></font>
</center><p>

<!-- Script Size: 5.27 KB -->
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP and MySQL ? rob2132 Hot Scripts Forum Questions, Suggestions and Feedback 4 08-29-08 02:22 AM
Database table contents to email problem (PHP and MySQL) blokeofftheinternet PHP 2 04-29-04 09:34 AM
PHP, MySQL, WML superman PHP 0 03-04-04 10:46 AM
Need Epinions-lite system in PHP & MYSQL wali001 Job Offers & Assistance 4 01-12-04 06:02 AM
Error when trying to select data off MySQL in PHP HasansWeb PHP 7 01-07-04 02:06 PM


All times are GMT -5. The time now is 04:35 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.