By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,460 Members | 1,095 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,460 IT Pros & Developers. It's quick & easy.

puttin javascript variable into hidden field

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a
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

P: n/a

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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.