email-feedback including screen resolution

Javascript coding ..

Moderators: macek, egami, gesf

Miss_Marple
New php-forum User
New php-forum User
Posts: 32
Joined: Tue Jul 30, 2002 11:27 pm

email-feedback including screen resolution

Postby Miss_Marple » Thu Aug 28, 2003 10:38 am

Hello

I use a mail()-feedback creating a html-mail on one page. The $textbody contains the html-code with all variables of the formular, trivial so far. But I want to get the user's screen-resolution in the feedback-mail as well. As I understand, the necessary javascript must already have been executed on the client, when the server runs the php-script with the mail-function. So do I need to send the js-variables containing the resolution-values from each page, which may direct to the mail-script? Could I get the resolution on index.htm an store it for later use, perhaps by passing it in the URL? I never did that before so I don't know how to pass it with js and how to read the values with php. Okokok - you might say RTFM but this question seems to be too simple for mentioning it in a manual.
The script I'm working on is on
http://www.herrnaumann.de/wandkunst/fra ... t/mail.php

Thank You for any help

Alex

User avatar
swirlee
Moderator
Moderator
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back
Contact:

Re: email-feedback including screen resolution

Postby swirlee » Thu Aug 28, 2003 11:31 am

My JavaScript is lousy, so I can't give you many specifics, but here's how I'd do it: On the page with the mail form, have a hidden form field, e.g.

Code: Select all

<input type="hidden" name="resolution" value="">


Then, on the page, put JavaScript that detects the resultion when the page loads and sets the value of the hidden form field to the detected resolution. Then, when the form is submitted, you can just add the contents of the field (e.g. $_POST['resolution']) to your e-mail message.

I hope that's helpful. You'll have to come up with the actual JavaScript on your own, unless someone else wants to provide it.

Miss_Marple
New php-forum User
New php-forum User
Posts: 32
Joined: Tue Jul 30, 2002 11:27 pm

I'm stuck

Postby Miss_Marple » Thu Aug 28, 2003 1:13 pm

It doesn't work. What I did in the <head> of this mail.php:
<script language="JavaScript">
var hoehe, breite, farbe, aufloesung;
high = screen.height;
wide = screen.width;
col = screen.colorDepth;
var resolution = wide + "x" + high + "Color:" + col;
</script>

In the form (action="mail.php"):
<input type="hidden" name="resolution" value="">

$res = $_POST['resolution'];

and in the html-body of the email I called $res. Nothing.Empty.
I don't know whether it's a simple script mistake or a basic misunderstanding of how php and javascript are executed. I thought, the javascript is run, when the page is loaded for the first time. The POST of the formular calls the same php-code again with the variables' values set in the form. Now where is the value of the hidden 'resolution' field...gone...Nirvana?

Help

Alex

Miss_Marple
New php-forum User
New php-forum User
Posts: 32
Joined: Tue Jul 30, 2002 11:27 pm

ooops

Postby Miss_Marple » Thu Aug 28, 2003 1:37 pm

of course I wrote:
var high, wide, col, resolution;

User avatar
swirlee
Moderator
Moderator
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back
Contact:

Postby swirlee » Thu Aug 28, 2003 1:56 pm

At some point you actually have to assign the value to the hidden form field. I'm not sure exactly, but once you have the visitor's resolution in the JavaScript variable "resolution", you should be able to put it into the form field like so:

Code: Select all

<input type="hidden" name="resolution" value="<script language="JavaScript">document.write(resolution)</script>">


Now don't just copy my code verbatim, because, as I said, my JavaScript is crap. I'm sure someone else around here can tell you if the above will work.

Miss_Marple
New php-forum User
New php-forum User
Posts: 32
Joined: Tue Jul 30, 2002 11:27 pm

good night

Postby Miss_Marple » Thu Aug 28, 2003 2:05 pm

Thank you so far...it's late. Try again tomorrow.

Alex

User avatar
ruturajv
php-forum Super User
php-forum Super User
Posts: 1280
Joined: Sat Mar 22, 2003 9:42 am
Location: Mumbai, India
Contact:

javscript

Postby ruturajv » Thu Aug 28, 2003 9:56 pm

here is an ans.

Code: Select all

<script language="JavaScript">
var hoehe, breite, farbe, aufloesung;
high = screen.height;
wide = screen.width;
col = screen.colorDepth;
var resolution = wide + "x" + high + "Color:" + col;
</script>

<input type='hidden' name=resolution value="document.write(resolution);">


now the php page where this info is posted

Code: Select all

<?php

//get the variable
//make sure the variable is posted via POST if passed via
// ur use $_GET['resolution']
$resolution = $_POST['resolution']

//use this variable using the mail fn.

mail(all the necessary info);

?>

Miss_Marple
New php-forum User
New php-forum User
Posts: 32
Joined: Tue Jul 30, 2002 11:27 pm

Aaaaah

Postby Miss_Marple » Fri Aug 29, 2003 3:29 am

Here was my mistake!
I thought the js could run in the <head> and that's ok. But I had to place it somewhere in the form or below !!!

Yippieh...it works

Thanks a lot

Have a nice weekend..as I will have it

Alex


Return to “JavaScript”

Who is online

Users browsing this forum: Google [Bot] and 1 guest