954,206 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

js problem

hi everyone,
I have some problem about simplifying my php code.
At first I want to load my form and then load my information from database if their are any data exists according to the user name.

Actually the problem is,I want to load the js while the information is their.

<?php
$data=mysql_fetch_array[$result];
if($data[0]!=0){
echo"?>
<script>
document.getElementById('text1').value="<?php echo $data[0]";
document.getElementById('text2').value="<?php echo $data[1]";
</script>
<?php
}

?>

thats it..!!

But I want to write it in my js.That will load if data exists.

If their have any alternative way??

ruman_eee
Newbie Poster
10 posts since Aug 2007
Reputation Points: 10
Solved Threads: 1
 

Well aside from the fact that it is syntactically incorrect. You aren't terminating the php blocks when you echo. Remember to end them with ?>. Aside from that, when you get the results find the number of results with mysql_num_rows then do a loop.

ShawnCplus
Code Monkey
Team Colleague
1,583 posts since Apr 2005
Reputation Points: 526
Solved Threads: 268
 

if im getting this right you are trying to insert some value from php into the js
if so you could do it like this

<?php  echo "<script>some-js-code-with-$varableName</script>";   ?>
w_3rabi
Junior Poster
160 posts since Dec 2006
Reputation Points: 18
Solved Threads: 9
 

also, be careful to escape the quotes in the javascript block if necessary

scru
Posting Virtuoso
1,629 posts since Feb 2007
Reputation Points: 975
Solved Threads: 140
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You