473,325 Members | 2,792 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

puttin javascript variable into hidden field

Hello
I wish to use J.S. to obtain the screen ht and put this value into a hidden
field for posting. so that I can then use it in a php file.
A simplified script of what I am trying to do is below, but it doesnt work.
I have not used javascript much and I'm sure its straight forward.
<script type="text/javascript" language="javascript">
var ht = document.body.clientHeight;
</script>

<form action="my.php" method="post">
input name="screenht" type="hidden" value="ht"
</form>

Thanks
Ian












Jul 6 '06 #1
5 3076
Ian Davies said the following on 7/6/2006 2:30 PM:
Hello
I wish to use J.S. to obtain the screen ht and put this value into a hidden
field for posting. so that I can then use it in a php file.
A simplified script of what I am trying to do is below, but it doesnt work.
I have not used javascript much and I'm sure its straight forward.
<script type="text/javascript" language="javascript">
var ht = document.body.clientHeight;
</script>

<form action="my.php" method="post">
input name="screenht" type="hidden" value="ht"
</form>
window.onload = setFormField

function setFormField(){
document.forms['formID'].elements['screenht'].value=ht;
}

But that still doesn't give you my screen height, it gives you my
browser window height.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Temporarily at: http://members.aol.com/_ht_a/hikksnotathome/cljfaq/
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jul 6 '06 #2
Ian Davies wrote:
Hello
I wish to use J.S. to obtain the screen ht and put this value into a
hidden field for posting. so that I can then use it in a php file.
A simplified script of what I am trying to do is below, but it doesnt
work. I have not used javascript much and I'm sure its straight
forward.
<script type="text/javascript" language="javascript">
var ht = document.body.clientHeight;
</script>

<form action="my.php" method="post">
input name="screenht" type="hidden" value="ht"
</form>

Thanks
Ian
I put clientheight form field into google and on the front page saw a hit
that said: "The effect of this is to encode the browser's viewport
dimensions in a hidden form field". It gives you a general method but
includes a lot more that you seem to be trying to do.
Basically it suggests having a submit buton script to populate the hidden
field (which should be identified by an ID for safety).

HTH
Jul 6 '06 #3

Randy Webb wrote:
Ian Davies said the following on 7/6/2006 2:30 PM:
Hello
I wish to use J.S. to obtain the screen ht and put this value into a hidden
field for posting. so that I can then use it in a php file.
A simplified script of what I am trying to do is below, but it doesnt work.
I have not used javascript much and I'm sure its straight forward.

if (self.innerWidth)
{
screenwidth = self.innerWidth;
screenheight = self.innerHeight;
}
else if (document.documentElement &&
document.documentElement.clientWidth)
// Explorer 6 Strict Mode
{
screenwidth = document.documentElement.clientWidth;
screenheight = document.documentElement.clientHeight;
}
else if (document.body) // other Explorers
{
screenwidth = document.body.clientWidth;
screenheight = document.body.clientHeight;
}

Try this...

Jul 6 '06 #4
Paul Lautman wrote:
<snip>
Basically it suggests having a submit buton script to
populate the hidden field
If a script dependent action needs to be carried out prior to the
submission of a form the form element's onsubmit handler is the most
direct and reliable place to carry out that action. Especially as many
browsers provide alternative mechanisms for triggering the submission of
a form, so any submit button may not be involved during the submission
of a form.
(which should be identified by an ID for safety).
Do you have any evidence for that strange assertion? If a hidden field
is to result in a name value pair being sent to the server (if it is to
be, in the language of the (X)HTML specification(s), "successful") then
it must have a name attribute, and traditionally, and by W3C HTML DOM
specification, named form controls are referencable by name in the form
element's - elements - collection. Indeed, in many browsers that
pre-date the W3C specification form controls cannot be referenced in
the - elements - collection by ID.

Richard.
Jul 6 '06 #5
Browser window ht is fine.
but i couldnt get your code to work
what order should it be in

ian

"Randy Webb" <Hi************@aol.comwrote in message
news:N4******************************@comcast.com. ..
Ian Davies said the following on 7/6/2006 2:30 PM:
Hello
I wish to use J.S. to obtain the screen ht and put this value into a
hidden
field for posting. so that I can then use it in a php file.
A simplified script of what I am trying to do is below, but it doesnt
work.
I have not used javascript much and I'm sure its straight forward.
<script type="text/javascript" language="javascript">
var ht = document.body.clientHeight;
</script>

<form action="my.php" method="post">
input name="screenht" type="hidden" value="ht"
</form>

window.onload = setFormField

function setFormField(){
document.forms['formID'].elements['screenht'].value=ht;
}

But that still doesn't give you my screen height, it gives you my
browser window height.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Temporarily at: http://members.aol.com/_ht_a/hikksnotathome/cljfaq/
Javascript Best Practices -
http://www.JavascriptToolbox.com/bestpractices/
Jul 6 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Kevin Lyons | last post by:
Hello, I am trying to get my select options (courses) passed correctly from the following URL: http://www.dslextreme.com/users/kevinlyons/selectBoxes.html I am having difficulty getting the...
13
by: Randell D. | last post by:
Folks, I have two related questions: 1. I have seen unicode being mentioned in my javascript pocket book - is this the same as ascii codes? I think not though I'm not sure and I can't find...
14
by: tshad | last post by:
I posted this on the asp.net group, also. I wasn't sure whether this was an asp.net problem or a javascript problem. I have a page that was originally created from a program I found on the net...
1
by: IkBenHet | last post by:
Hello, I found this script to create a simple rich text form (http://programmabilities.com/xml/index.php?id=17): <html> <head> <title>Rich Text Editor</title> </head> <body>
4
by: Shawn Repphan | last post by:
I apoligize if this is out of scope with this group. I have a textbox that displays a current record number(xx of xxx). The user has the ability to enter their own number into this box and perform...
6
by: wolfing1 | last post by:
how would I go doing it without javascript and using 'POST'? Having a page with a variable list of items in a shopcart, each item with its own 'remove' button. How could I do this without a...
7
by: shil | last post by:
Hi all, Can any one direct me in how to use javascript confirm() function when a condition is met from codebehind. I don't want to attach this to a button. When I submit the page, I want to...
2
by: sorobor | last post by:
dear sir .. i am using cakephp freamwork ..By the way i m begener in php and javascript .. My probs r bellow I made a javascript calender ..there is a close button ..when i press close button...
2
Frinavale
by: Frinavale | last post by:
Hi! I am dynamically generating external .js JavaScript resources to be used with a Tab control I created (using VB.NET). Originally, the JavaScript was written directly into the <head> of the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.