Question

I try to read a string from REQUEST_PHP, which is a string containing commas, separating the values of an array. I save the index value of selected elements of a list to an array. I join them and then use console.log and an alert box to confirm the values are there. For instance say its a list of 8 items and numbers 1,2,4,6 are selected. console.log displays (1,2,4,6) i use document.getElemenetById and set the value to value of join(array) and console.log shows the values are there correctly but when i go to submit the form and print php results on the subsequent page, or submit them to MySQL database the values for the selected item list is blank. Other aspects of the form submit fine via php. Have been messing with this for hours and tried numerous things any help would be appreciated.

Here's relevant code

Javascript:

var testies= "";
$(function() {
    $( "#Testing1" ).selectable({
        stop: function() {
        var selectedNumbers = "";
        $( ".ui-selected", this ).each(function(i) {
            if(i != 0) {
                selectedNumbers += ",";
             }
             selectedNumbers += $(this).index()+1;           
           });
           console.log(selectedNumbers);
            var poop = [selectedNumbers];
            testies = poop.join();
            console.log(testies);
            document.getElementById("placeholder").value = testies;
         }

    }); 
});

function showAlert() {
  alert(placeholder.value);
};

HTML:

<div id="placeholder"></div>

<strong>&#149; Select Options? </strong> (select all that apply)
        <ol id="Testing1" class="multiclicklist">
            <li input type="checkbox" class="ui-state-default" name="testing2[]" class="checkbox" value="1">Opt 1</li>
            <li input type="checkbox" class="ui-state-default" name="testing2[]" value="2">Opt 2</li>
            <li input type="checkbox" class="ui-state-default" name="testing2[]" value="3">Opt 3</li>
            <li input type="checkbox" class="ui-state-default" name="testing2[]" value="4">Opt 4</li>
            <li input type="checkbox" class="ui-state-default" name="testing2[]" value="5">Opt 5</li>
            <li input type="checkbox" class="ui-state-default" name="testing2[]" value="6">Opt 6</li>
            <li input type="checkbox" class="ui-state-default" name="testing2[]" value="7">Opt 7</li>
            <li input type="checkbox" class="ui-state-default" name="testing2[]" value="8">Opt 8</li>
        </ol>

        <br>
        <input type="button" value="CheckValue" onclick="showAlert();"> 

PHP Code:

$active = trim($_REQUEST['placeholder']);
 print($active);

I'm a little frustrated so any help be very welcom

Was it helpful?

Solution

change

<div id="placeholder"></div>

to

<input id="placeholder" name="placeholder" />

Assuming you have everything inside a proper <form>.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top