Hello All, I am new to PHP @ 1 week. So borrowing code anywhere I can. I am making progress, but hit a snag.
I have 2 list boxes, that I use to move items left to right. When I click submit I want to load the items selected into MySQL. Is anyone able to help please? I can do the insert into MySQL (i think), but i cant work out how to get the values into a variable that PHP can use to submit.
Then to make it more complicated, once I have it working for 1 list, I ideally wany about 10 lists on the page (with only 1 submit box). I am lost.
Thanks
greg
Code: This is my OPTION.js file
var selectedList;
var availableList;
function createListObjects(){
availableList = document.getElementById("availableOptions");
selectedList = document.getElementById("selectedOptions");
}
function delAttribute(){
var selIndex = selectedList.selectedIndex;
if(selIndex < 0)
return;
availableList.appendChild(selectedList.options.item(selIndex))
selectNone(selectedList,availableList);
setSize(availableList,selectedList);
}
function addAttribute(){
var addIndex = availableList.selectedIndex;
if(addIndex < 0)
return;
selectedList.appendChild(availableList.options.item(addIndex));
selectNone(selectedList,availableList);
setSize(selectedList,availableList);
}
function delAll(){
var len = selectedList.length -1;
for(i=len; i>=0; i--){
availableList.appendChild(selectedList.item(i));
}
selectNone(selectedList,availableList);
setSize(selectedList,availableList);
}
function addAll(){
var len = availableList.length -1;
for(i=len; i>=0; i--){
selectedList.appendChild(availableList.item(i));
}
selectNone(selectedList,availableList);
setSize(selectedList,availableList);
}
function selectNone(list1,list2){
list1.selectedIndex = -1;
list2.selectedIndex = -1;
addIndex = -1;
selIndex = -1;
}
function setSize(list1,list2){
list1.size = getSize(list1);
list2.size = getSize(list2);
}
function getSize(list){
/* Mozilla ignores whitespace, IE doesn't - count the elements in the list */
var len = list.childNodes.length;
var nsLen = 0;
//nodeType returns 1 for elements
for(i=0; i<len; i++){
if(list.childNodes.item(i).nodeType==1)
nsLen++;
}
if(nsLen<2)
return 2;
else
return nsLen;
}
function showSelected(){
var optionList = document.getElementById("selectedOptions").options;
var data = '';
var len = optionList.length;
for(i=0; i<len; i++){
if(i>0)
data += ',';
data += optionList.item(i).value;
}
alert(data);
}
Code: This is my edit.php file
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Test</title>
<script type="text/javascript" src="option.js"></script>
</head>
<body onload="createListObjects()">
<?php
echo" <select name="selectedOptions[]" id="selectedOptions" multiple="true"> "; //start the select box
echo "<option value="1">Cat</option>n"; //and place it in the select
echo "<option value="2">Dog</option>n"; //and place it in the select
echo "</select>"; //close the select
?>
<button onclick="addAttribute()"><</button>
<button onclick="addAll()"><<<</button>
<button onclick="delAttribute()">></button>
<button onclick="delAll()">>>></button> </td>
<?php
echo" <select name="availableOptions" id="availableOptions" multiple="true"> "; //start the select box
echo "<option value="3">pig</option>n"; //and place it in the select
echo "</select>"; //close the select
?>
<tr>
<td colspan="2"><button
onclick="showSelected()">
Submit</button> </td>
</tr>
</body>
</html>
Code: <html><body>
<?php
$data = $_POST['selectedoptions'];
I AM LOST HERE
echo "Data Inserted!";
?>
</body></html>
Probably a simple error...
I'm getting the error -- Parse error: syntax error, unexpected '{' in /home/content/c/s/t/csteffen242/html/staples/event.php on line 46I checked it over and couldn't find anything wrong with an extra
output printing as hexadecmal... XD
Everything works except the calcem call for the totusold and totuprice. The out put shows up as hex. Im not positive but i think i might have to use PBV or PBR?
How to convert this array to string
I am having problems converting this array to a stringusing print_r($val[1]); I get: Code: [Select]Array( [0] => Array ( [name] => John ) [1] =>
PHP template help
Ok, I don't know if anyone can help me but I am using PHP templates to make a site. I am a newbie and so I am finding this quite difficult so I thought I would ask some folks much better than me. I
Generate multilayered array from string.
ok so i have a string that looks like this:Code: blog:edit_all,delete_all|users:edit_all,delete_all|settingsand i want to make a code that can take that string and put it in a multi-layered array like
send() and recv() parameters confusion
On server Side:
Text Not Displaying Correctly With PHP:GD
I recently moved servers and since then I have noticed that one line of text is showing weirdly.I have attached an example image that was generated. In the word 'Managing' the letters M & N
Calculus Help (and by help I mean homework)
Hrmmm, I hate posting about math homework, partly because it's homework, and partly because I hate whenever I can't figure out math myself.Yes, I realize this is an extremely long post. Feel free to
How to show next and prev records
Hi all,Sorry if this is simple, i'm very new to php, well, any programming language actually.My code runs a query and comes back with the results. Very rarely there may be more than one result.I have
printing links
Hi every1i am connecting to a table in sql and the looping through with a while ($ var = my sql fetch array)the question i have is that when i print_r($var)i get the associative array of all elements