paul2463 Posted October 24, 2006 Share Posted October 24, 2006 I realise the server / client side argument of the two languages I was just wondering if there was a way around my little problemI have a page that allows a person to add a type of material a piece of equipment is made of, I have a javascript function that initiates a window.prompt() dialog box in fact code first questions later[code]//javascript function function addMaterialType() {var $answer = window.prompt("Enter a new material");if ($answer != "") {<?=InsertMaterial($answer)?>; // a php function to add the material to the database}}[/code]now...... if I place a value in the php function call i.e. [code]<?=InsertMaterial("Wood")?>;[/code]the function works beautifully, adding Wood , but only Wood everytime of coursebut as the origonal function stands it adds nothing to the database because the php function does not recognise the javascript variable even though its starts with a $, is there any way I can make this function work as it should or do I have to start thinking in a new direction all together?many thanks in advance Quote Link to comment Share on other sites More sharing options...
obsidian Posted October 24, 2006 Share Posted October 24, 2006 There is no way to get your javascript to populate a PHP variable in that way. Think of it like this: by the time your page loads, your PHP code is not there any longer. It has already been parsed out by the server. You only have HTML and Javascript code available to the browser. So, when your Javascript function runs, there actually is no PHP variable to be populated. If you are wanting to allow a Javascript function to update a database or other database content on your page, you'll need to make an HTTP request and send the value of your variable to another script to run your update for you. Quote Link to comment Share on other sites More sharing options...
paul2463 Posted October 24, 2006 Author Share Posted October 24, 2006 Thanks for that Obsmuch appreciated Quote Link to comment Share on other sites More sharing options...
scottybwoy Posted October 25, 2006 Share Posted October 25, 2006 If you look at some ajax examples like this one http://www.tizag.com/ajaxTutorial/index.php you will see how you can use events to triger a call to your php page, also parse variables to your php and get the php to send strings to the javascript to work with. Database action is a bit more tricky, but with a little google action I'm sure you can work it out ;) Quote Link to comment 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.