Results 1 to 2 of 2

Thread: Setting javascript variable equal to php variable by passing a parameter

  1. #1
    Join Date
    Aug 2011

    Setting javascript variable equal to php variable by passing a parameter

    I am having problems with the following. I am wanting to hide <tr> in my table (employees) and only show employees that are in the selected department (selected via dropdown box).
    I need to set a javascript array to a php array. I am looping and assigning the array and am wanting to pass a javascript variable as the index in php array. I have marked my problem lines in red. Thanx for any help.
    <script type="text/javascript" >  
        function display_elements()
                     var departments = new Array; 
                     var dep_element_counter = new Array;
    		 var dep_count = "<?php echo count($departments); ?>";
    		 var e = document.getElementById("jdepartment");
                     var sel_dep_id = e.options[e.selectedIndex].value;
    		 var id;
    	         departments[x] = "<?php echo $departments[" + x + "]; ?>";
    		dep_element_counter[departments[x]] = "<?php echo $dep_emp_counter[$departments[" + x + "]]; ?>";
                     if(departments[x] == sel_dep_id)
                     {document.getElementById(id).style.display = "";
    		{document.getElementById(id).style.display = "none";

  2. #2
    Join Date
    May 2011

    maybe this


    new Array is non constructor, new Array() is a constructor

    var departments = new Array(); // values are indexes for dep_element_counter[departments[x]]
    // string index possible ?

    var dep_element_counter = new Array(); // values are stings

    x is an index

    departments[x] = "<?php echo $departments[" + x + "]; ?>"; // index is a string

    dep_element_counter[departments[x]] = ....

    document.write(dep_element_counter[departments[x]]); // document.write() maybe create a new document

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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