Php/Javascript pop up dynamic variable.

Posted on 2011-04-29
Last Modified: 2012-05-11
Hi Experts,

I need help with this, what im after is a Javascript pop up window which will let me Dynamicly define a PHP variable. if thats possible.

The variable i would like to try and define is.

below in my code called "$devideby ="

i dont have a clue how to do this as javascript pop up so really am in the dark. if you could help me with this it would be appricated. the variable of $devideby will be set as a number if that helps from 1 - 12.

many thanks for your time.

p.s if you know of a way of doing this just using php then please tell me. It needs to be set everytime you visit the page. and then the page updated with the variable after it has been set to show the "correct maths"

exmaple would be $variable 1 / $devide by = $variable 3

many thanks again.
$digits =2;
	$out_fee = $sum_total;
	$avgyr = $sum_total;
	$cutoff = pow(10, $digits);
	$divideby = 
	$rounded2 = round($avgyr * $cutoff / $divideby) / $cutoff;
	echo "<html><font color=' #003F87'><strong>£".$rounded2;"</strong></font></html>";

Open in new window

Question by:NeoAshura
    LVL 82

    Expert Comment

    by:Dave Baldwin
    You can't set a PHP variable with javascript because PHP runs on the server to create the page before the javascript runs in the browser that displays the page.  After a page is loaded, you can use AJAX to pass a value back to a PHP script but that is still after the page has already loaded.
    LVL 6

    Author Comment

    so the best way would be to create a dynamic variable using PHP rather than Java?
    LVL 82

    Accepted Solution

    I have no idea what that means.  For PHP to generate a page using a variable value, it must have that value when the page is 'called', either thru a POST or a GET from the previous page or from another value stored somewhere.  And it needs it when it generates that page.  Javascript is Not Java, two different languages.
    LVL 6

    Author Closing Comment

    used post
    LVL 82

    Expert Comment

    by:Dave Baldwin
    Cool, thanks.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    Article by: DanRollins
    This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (, we'll extend the program by adding a depth-…
    Part of the Global Positioning System A geocode ( is the major subset of a GPS coordinate (, the other parts being the altitude and t…
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now