Hey all!

This is perhaps more of a javascript problem, although it's when using it with php.. so I'm hoping someone might know how to help!

I'm using some javascript to add and remove select options from a list in HTML. However, due to php wanting the list to be submitted as an array for multiple select (with []) my javascript is throwing errors..

So basically, I want to make..

onclick="addSelected('form','complete_list','selected_list')

This

onclick="addSelected('form','complete_list','selected_list[]')

But without returning the errors, does anyone know if there's a way of putting backslashes with the [] or something similar to ignore them? (that doesn't work by the way!).

Any help would be greatly appreciated ; although, I appologise for this not being an entirely PHP question.. hope someone can help still!

Thanks 😃

    whats the whole line of the code

    <php ....
    onclick=.....

    or is it part of html and your doing onclick.....('<php $form .....

    ??

      Sorry, yes it's a javascript activated by a HTML form..

      <input type="button" onclick="addSelected('form','complete_list','selected_list')" value="&gt;&gt;">
      <select name="complete_list" size="10" multiple>
         <option value="Value">Name</option>
      </select> ... etc

      Is what I have now and it works, but I need to somehow make the name the list select of "selected_list" selected_list[] so that when submitted PHP recognises it as an array, so all selected items are submitted and not just the last on the list (as a single variable)..

      However when I put the name in the javascript as name[] it returns errors.. I was wondering whether it was possible to just make it ignore the brackets and take it as part of the name, rather than thinking its an array (which I assume would mean a rework of the whole javascript code to work differently..) hmm

        Ahh, nevermind.. 5 hours of searching later, and I've found the answer!

        I've ended up using this to select the HTML LIST by it's ID and not the name..

        getElementById("completeList");
        

        So the ID is completeList but the name is completeList[] for php 😃

          But I've not got another problem, which is that although my javascript adds the options to the list.. technically the list is empty in the html code.. so nothing submits anyway.. 🙁

            Write a Reply...