I have 2 lists - master and category. When moving items from master list to category list I can save category list with new values but unable to save master list with removed items. I was thinking of means of reading master list into hidden field of category list but not sure how to go about. Need help with this and herewith my code:-
it is exactly the same i only need to save the master list box value after moveto or move from which i just cant get right so i made a new post to address this> paul suggested using ajax i spen the whole day reading and trying to implement but i could only save the selected remove item to be saved and not the whole list
Perhaps you could post the code you tried to use, so people can comment on why it isn’t working. I take it the “quick and dirty” suggestion I made didn’t work either.
I feel I am moving in the right direction but still can’t seem to reach my end goal. For now I have added function to get value by getElementById
<script>
function getValue()
{
var master=document.getElementById("master");
for (var i = 0; i < master.options.length; i++) {
if(master.options[i].selected ==true){
alert(master.options[i].selected);
}
}
}
</script>
and here my js I have put alert(txt); in code to see if I get the right values which I do
<script>
function displayResult() {
var x = document.getElementById("master");
var txt = "All options: ";
var i;
for (i = 0; i < x.options.length; i++) {
txt = txt + "\n" + x.options[i].value;
}
alert(txt);
}
</script>
Is that going to work? You get element by ID using “master”, but the element with id=master is your hidden form field, which is empty. So how do you get the correct things displayed, what is putting things into your hidden form field?
You might want to look at encoding the array before you put it into the hidden form field and decoding it in your PHP, I think that might be confusing matters. JSON-encoding might do it.
Yes, I got so far now by getting the value I must just see how to put contents in file. Herewith my update code.
<script>
function displayResult() {
var options = document.getElementById('master').options;
var values = [];
var i = 0, len = options.length;
while (i < len)
{
values.push(options[i++].value);
}
txt=(values.join(', '));
alert(txt);
document.getElementById('masterlist').value = txt;
}
</script>