Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
| Search | Today's Posts | Mark Forums Read
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old October 29th, 2006, 04:07 PM
Authorized User
Join Date: Apr 2006
Location: bikaner, raj, India.
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to chayanvinayak
Default adding php code in javascript

How can i add php script inside javascript function with variable of javascript .

so far i have tried following but its not working :

var any=100;
document.write("<?php mysql_query(\"INSERT INTO table VALUES "+any+"") ?>");

chayan vinayak goswami
chayan vinayak goswami
  #2 (permalink)  
Old October 31st, 2006, 05:37 AM
Friend of Wrox
Join Date: Oct 2004
Location: delhi, delhi, India.
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to vinod_yadav1919 Send a message via Yahoo to vinod_yadav1919

Hi Vinayak!!
You can't do this,since ur php code is server side script, and ur client side javascript variable can't be accessed at the same time.
you can use ajax or use iframe to share the client side variables with server side scripts.
hope this will help you

Cheers :)

  #3 (permalink)  
Old December 18th, 2006, 02:33 AM
Friend of Wrox
Join Date: Oct 2003
Location: colombo, WP, Sri Lanka.
Posts: 479
Thanks: 0
Thanked 3 Times in 3 Posts
Send a message via MSN to surendran Send a message via Yahoo to surendran

try this, but i don't know how this working
<script language="JavaScript" type="text/javascript">
<!-- //
var any=100;
document.write(<?php echo any?>);
// -->

(Anything is Possible)

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to embed javascript in php code scoobie PHP How-To 8 November 28th, 2007 02:11 PM
adding checkbox to datagrid using javascript k.manisha ASP.NET 1.0 and 1.1 Professional 0 June 4th, 2007 11:02 PM
adding items to list box using javascript k.manisha ASP.NET 1.0 and 1.1 Professional 3 February 16th, 2007 06:32 AM
adding a class in JavaScript crmpicco Javascript How-To 5 October 4th, 2005 08:15 AM
Adding javascript to popups chrscote Javascript How-To 2 June 8th, 2005 04:34 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.