optikalefx Posted August 5, 2007 Share Posted August 5, 2007 Iv seen a lot of topics about javascript to php but not the other way around I run a sql query to get the number of rows in a table and i want that variable to be able to be used in javascript the javascript is this <script language="text/javascript"> function formSubmit() { var a; a = <? echo $nrows; ?>; alert(a); document.frmupload.hdnupload.value=true; document.frmupload.submit(); return true; } the reason it has to be in javascript is because an html form uses onClick="return formSubmit();" so its not php anymore well the function is in javascript but i want to bring in variable $nrows which has a number. ill do the if statement after im able to see that javascript has the number. any ideas on how to get javascript the php variable? oviously the example i posted doesnt work. and yes $nrows does exist because Iv echoed it and its there. Quote Link to comment https://forums.phpfreaks.com/topic/63381-php-variables-to-javascript/ Share on other sites More sharing options...
optikalefx Posted August 5, 2007 Author Share Posted August 5, 2007 nevermind i developed a workaround Quote Link to comment https://forums.phpfreaks.com/topic/63381-php-variables-to-javascript/#findComment-315941 Share on other sites More sharing options...
tomfmason Posted August 5, 2007 Share Posted August 5, 2007 that should work fine. I have been doing things exactly that way for a long time. Also, if you are already using short tags you could do away with the echo. Like this: <?=$a; ?> for more info see alternative php syntax or http://codeigniter.com/user_guide/general/alternative_php.html Quote Link to comment https://forums.phpfreaks.com/topic/63381-php-variables-to-javascript/#findComment-315944 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.