Jump to content

javascript variable to php variable number/math problems


Lucent

Recommended Posts

Hiya,

This is my first time to post here so please forgive me if i've done it a bit wrong, or put it in the wrong section. But as my code start in javascript and thr trouble could be there, I've put it here... but of course the trouble could be in just my php.

 

to sum up what i'm trying to do is adjust the number of (fixed size) columns to display on the page depending on the users resolution (hence the javascript).

 

Here are the snippets of code that are relevant, there is too much code to post the whole lot

 

in the <head>

<script type="text/javascript">
var Width = screen.availWidth
</script>

 

then to pass this java variable to php i'm using a form (best way i could find)

this is only done the first time the page is visited (during login)

<input type="hidden" name="width" value="<script>document.write(Width);</script>" />

 

then set to a session variable with

if(isset($_POST['width']))
$_SESSION['width'] = $_POST['width'];

 

$maxcellcount1 = $_SESSION['width'];
echo $maxcellcount;
echo gettype($maxcellcount1);

this outputs 1024 (well for me at the moment) & string (I know it's not the best method to use to find the type, but i had to know)

I figure string is good here but i try some maths

$maxcellcount1a = $maxcellcount1/250;
echo $maxcellcount1a;

and this gives 0

so trying settype..

settype($maxcellcount1, float);
$maxcellcount1a = $maxcellcount1/250;
echo $maxcellcount1a;

this also gives 0

 

i'm going to stop with the code there as anything else doesn't work as this is clearly a stop point, but i'm not sure why this doesn't work.

 

I've tried a few different ways of fiddlign the code, I have also tried to aplied the maths that i want to do to the value in the original javascript

var StatusCells = Math.floor(Width/250);

and following through an identical process (apart from the last bit of maths i get the same results as far a it's a string though it is a four (as it should be) but when used in an if statment against a counter it well doesn't work... i can give the code for that bit too, but this post is too long already.

 

If anyone can help, I'd really appriciate it as I just can't figure out what is wrong!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.