User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 455,985 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,759 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 367 | Replies: 3
Reply
Join Date: Aug 2007
Posts: 10
Reputation: ruman_eee is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 1
ruman_eee ruman_eee is offline Offline
Newbie Poster

Help js problem

  #1  
Dec 4th, 2007
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??
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Apr 2005
Location: New York state
Posts: 487
Reputation: ShawnCplus will become famous soon enough ShawnCplus will become famous soon enough 
Rep Power: 5
Solved Threads: 73
Sponsor
ShawnCplus's Avatar
ShawnCplus ShawnCplus is offline Offline
Code Monkey

Re: js problem

  #2  
Dec 4th, 2007
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.
GCS d- s+ a-->? C++(++++) UL+++ P+>+++ L+++ E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h-->++ r z+*
Reply With Quote  
Join Date: Dec 2006
Location: syria
Posts: 158
Reputation: w_3rabi is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 8
w_3rabi's Avatar
w_3rabi w_3rabi is offline Offline
Junior Poster

Re: js problem

  #3  
Dec 6th, 2007
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>";   ?>
programming is an art ,only for those who can understand it.
- th3 php wr3nch -
Reply With Quote  
Join Date: Feb 2007
Location: St. Vincent and the Grenadines, Caribbean
Posts: 1,032
Reputation: scru is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 47
Featured Poster
scru's Avatar
scru scru is offline Offline
Veteran Poster

Re: js problem

  #4  
Dec 6th, 2007
also, be careful to escape the quotes in the javascript block if necessary
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 9:28 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC