/    Sign up×
Community /Pin to ProfileBookmark

passing data from PHP to Javascript

Hi,

May someone help me here. Am trying to read a database value in a javascript. I have used an alert() function to output the value passed from php to javascript. I get nothing in all my attempts. Someone help me.

I have only cut a piece of code that givens problem.

Thank you in advance.

Mutua

<script type=”text/javascript”>
function closeWin()
{
var myFileNoX = document.getElementById(‘fileNo’);
alert(myFileNoX.value);
close();
}
</script>

<!– form –>
<FORM NAME=”forward” ACTION=”<?php $_SERVER[‘PHP_SELF’]; ?>” METHOD=”POST” >
<table width=”75%” border=”1″ align=”center” >
<tr>
<td width=”196″><strong>File Number</strong></td>
<?php do { ?>
<td><?php echo $row_qry[‘fileNo’]; ?> </td>

<td>
<INPUT TYPE=”HIDDEN” NAME=”fileNo” id =”fileNo” value = “<?php $fileNo; ?>” >
<input type=”submit” value=”Select” onClick =”closeWin()” />
</td>
</tr>

<?php
} while ($row_qry = mysql_fetch_array($result)); ?>

</table>
</form>

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@tirnaJan 30.2011 — Where is $result set in your code?

You are also trying to access $row_qry['fileNo'] in the first pass of your do-while loop before it is set in the while part of the loop. Try using just a while loop.

"<?php $fileNo; ?>" - you need to actually echo $fileNo
Copy linkTweet thisAlerts:
@kakinyimauthorJan 30.2011 — Where is $result set in your code?

You are also trying to access $row_qry['fileNo'] in the first pass of your do-while loop before it is set in the while part of the loop. Try using just a while loop.

"<?php $fileNo; ?>" - you need to actually echo $fileNo[/QUOTE]


@Tirna,

i have only copied the area with problem. At this form, i can echo $fileNo but it doesnt get passed to javascript. Where am i going wrong?
×

Success!

Help @kakinyim spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...