Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jun 2009
    Posts
    6
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Required naming syntax breaks functions

    Hey all,

    I have 2 select windows and have a function to move items from one select window to another. That was working fine until I had to change the names of each box in order to be able to post the select window as an array in PHP.

    Code:
    <select size="10" name="select_list1[]" id="select_list1[]" MULTIPLE>
    Code:
    <select size="10" name="select_list2[]" id="select_list2[]" MULTIPLE>
    This is the function call:
    Code:
    <input type="button" value=" --> " onClick="SelectMoveRows(document.form.select_list1, document.form.select_list2);"/>
    And this is the function that moves the options from one window to the other:

    Code:
    	function SelectMoveRows(SS1,SS2) {
    		var SelID='';
    		var SelText='';
    		
    		// Move rows from SS1 to SS2 from bottom to top
    		for (i=SS1.options.length - 1; i>=0; i--) {
    			if (SS1.options[i].selected == true) {
    				SelID=SS1.options[i].value;
    				SelText=SS1.options[i].text;
    				var newRow = new Option(SelText,SelID);
    				SS2.options[SS2.length]=newRow;
    				SS1.options[i]=null;
    			}
    		}
    	}

    The errors I am getting now are:

    Error: SS1 is undefined

    and if I try to change the function call (adding []'s), I get a syntax error because of it.

    Error: syntax error
    Source Code:
    SelectMoveRows(document.form.select_list1[], document.form.select_list2[]);

    How can I change the functions so that it accepts the square brackets? They are necessary unless you know of a better way to post a select form in PHP.

    Thanks for any information.

  • #2
    Banned
    Join Date
    Nov 2008
    Location
    not found
    Posts
    284
    Thanks
    0
    Thanked 53 Times in 51 Posts
    Try:
    Code:
    onClick = "SelectMoveRows( document.form[ 'select_list1[]' ], document.form[ 'select_list2[]' ] );"

  • Users who have thanked randomuser773 for this post:

    Buzzle (06-23-2009)

  • #3
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    I don't think the square brackets are required on the id attribute - just the name. After a glance at google, some posts suggest that square brackets on the ID may cause inconsistent behavior.
    Are you a Help Vampire?

  • #4
    New to the CF scene
    Join Date
    Jun 2009
    Posts
    6
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Thanks randomuser, that worked. Javascript syntax always seems to surprise me. I never really sat down to thoroughly investigate it.

    @tomws, Thanks for the advice. I don't normally do that, I was just frustrated and trying everything to get it to work. I'll likely take it out since I am not really even using the id for anything.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •