473,799 Members | 3,061 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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="javas cript">
var ht = document.body.c lientHeight;
</script>

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

Thanks
Ian












Jul 6 '06 #1
5 3123
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="javas cript">
var ht = document.body.c lientHeight;
</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.javas cript 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="javas cript">
var ht = document.body.c lientHeight;
</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.innerWidt h)
{
screenwidth = self.innerWidth ;
screenheight = self.innerHeigh t;
}
else if (document.docum entElement &&
document.docume ntElement.clien tWidth)
// Explorer 6 Strict Mode
{
screenwidth = document.docume ntElement.clien tWidth;
screenheight = document.docume ntElement.clien tHeight;
}
else if (document.body) // other Explorers
{
screenwidth = document.body.c lientWidth;
screenheight = document.body.c lientHeight;
}

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="javas cript">
var ht = document.body.c lientHeight;
</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.javas cript 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
6559
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 courses to pass the correct option value and then be displayed at the following URL: http://www.dslextreme.com/users/kevinlyons/selectResults.html I am passing countries, products, and courses. The first two display
13
9066
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 any examples... 2. How do I read/set a string to an unprintable code? For example, how can I set the variable a to equal the equivalent of ascii code 7 or 8 or
14
5486
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 that works well as an html page. It brings up a modal popup window that I have been trying to work out for days now and this was the closest I have been able to come. I added a little asp.net code and an asp.net button and cannot get it to
1
3772
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
284
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 a postback to get the n'th record. I have client-side script that checks to see if any fields have changed so that the user doesn't accidently lose any updated info. If any fields have changed a javascript confirm box pops up. The only issue with...
6
2426
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 javascript and using POST as the form type? (so having <a href="page.htm?remove=2> is not possible)
7
5212
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 check some business rules, and based on the response from the database, if the response is Yes, I need to display a confirmation alert to user. When the user clicks ok, then I should take an action, if not, exit out of the subroutine. Below is the...
2
3158
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 then the calender gone actually i want if i click outside off the calender then it should me removed ..How kan i do this ... Pls inform me as early as possible .. I am waiting for ur quick replay ...Here i attached the source code .... <!DOCTYPE...
2
2221
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 pages that used Tab controls. Because it was generated in this way I was able to specify which tab was to be displayed as the "current" tab upon rendering the page in the browser. Since the JavaScript is now a fixed resource that resides on the...
0
9686
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10475
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10222
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10026
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9068
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6805
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4139
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3757
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.