-5

i have this dropdown list and i need to save it's value by javascript but i can't get the name of the php variable (select name ) into the function

drop down list :

   $i=0;
   while($i<$counter)
        {
      $vname=$row['student_id'].'_'.$i;
        echo"
          <td>

            <select name=".$vname.">
  <option value="."0".">Choose one</option>
 <option value="."1".">Add</option>
 <option value="."2".">R</option>
 <option value="."3".">TBR</option>
 <option value="."4".">P</option>
      </select>
   </td>";
       $i++;
            }

java script function :

           <script src="https://code.jquery.com/jquery-1.9.1.min.js"></script>                               
                     <script>
                 $(document).ready(function() {

             var item = window.localStorage.getItem('".$vname."');
              $('select[name=".$vname."]').val(item);

           $('select[name=".$vname."]').change(function() {
                 window.localStorage.setItem('".$vname."', $(this).val());
                 });

               });  
            </script>
5
  • We need to see the PHP code behind the Javascript code. Commented Mar 18, 2016 at 18:53
  • Also the select name is not between quotes Commented Mar 18, 2016 at 18:53
  • Nor are the option values. Commented Mar 18, 2016 at 18:54
  • I recommend CTRL+A and then DELETE. Do it all over again after reading some tutorials. Commented Mar 18, 2016 at 18:54
  • Also go and read up about proper use of string concatenation – <option value="."0"."> doesn’t do what you probably think it does. Commented Mar 18, 2016 at 19:09

1 Answer 1

0

You can do it like this: var vname = "<?php echo $vname; ?>";

Then replace $vname with vname in your javascript functions.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.