0

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

3 Answers 3

1

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

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

Comments

0

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.......

3 Comments

Also you may want to view source on your page and confirm that the script is actually getting rendered as such and not text. It looks ok though.
I believe it is okay since Javascript allows var a = b = 3;
Yes, also, I'm not that familiar with PHP but I'm willing to bet there is a built in way to do this.
0

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.

1 Comment

I agree we need to see all of your code and the way you have it would run top to bottom which would cause it not to be seen as Invisal mentioned

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.