kitara
kitara

Reputation: 1

need help on php with javascript

I need help on some update like function:

<html>
$result = mysql_query("SELECT *FROM tbl_a LEFT JOIN tbl_b lass ON tbl_b.b_id=a.class_id LEFT JOIN category ON category.category_id=tbl_a.category_id WHERE list ='{$id}'"); </br>
      while($row = mysql_fetch_array($result)){ 
     $id_list = $row['id']; 
      $name = $row['name'];
      ....
     }
    }
    echo "<script type='text/javascript'>
     var id = document.getElementById('list').value = '.$id_list;'  
     var name = document.getElementById('fname').value ='.$name;'   
    </script> ";
</html>

my problem is that i can retrieve data but it not displaying on my input elements it should be like an update function

Upvotes: 0

Views: 73

Answers (3)

Vlad
Vlad

Reputation: 3645

Quotes, quotes...

    echo 
    "<script type='text/javascript'>
    var id = '".$id_list."',
    name = '".$name."';

        document.getElementById('list').value = id;  
        document.getElementById('fname').value = name;
    </script> ";

Working example: http://codepad.viper-7.com/3eI3Od

Upvotes: 1

invisal
invisal

Reputation: 11171

If what you posted is the complete code, then there is no list and fname elements. Better open the page and view the source code to see if you have the right value written into your Javascript.

NOTE:
Remember that if you put your Javascript after the element HTML, Javascript cannot retrieve the element. For example:

<script>
    document.getElementById('test').value = 'Hello World';
</script>
<input type='text' id='test' value=''>

As you can see, it does not assign value to test element. Solution,

<input type='text' id='test' value=''>
<script>
    document.getElementById('test').value = 'Hello World';
</script>

Put the input before the Javascript.

Upvotes: 0

Judson Terrell
Judson Terrell

Reputation: 4306

You need to call your input elements and then give them the new values instead of setting variables like you are doing. Remove the "var something =" and just do document.get.......

Upvotes: 0

Related Questions