Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting the contents of a hidden field in my form

Status
Not open for further replies.

gameon

Programmer
Feb 23, 2001
325
GB
Hi, I am trying to get some of the info from my users, such as their screen size etc.

I wanted to get the page to put the result of:
<script language=&quot;JavaScript&quot;>document.write(window.screen.colorDepth)</script>

into one of the fields in my form, called 'screen width'.

I tried using an 'on-load' action to set the contents, but was unsucessful.

Can anyone help?

Cheers,

mailto:mattg@3rd-angle.com
Matt
 
document.formname.hiddenfieldname.value = window.screen.colordepth

where formname is the name you gave to the form which handles the hidden field (which name should be hiddenfieldname)
 
I'm probably being a moron.

My brain's fried from doing this site.
(mp3players.co.uk).

I've used the following to test, unsucessfully. What am I doing wrong?

Cheers,

Matt

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;>
</head>

<body bgcolor=&quot;#FFFFFF&quot;>
<p>


<script language=&quot;JavaScript&quot;>document.form1.screen_width.value = (window.screen.width)</script>



</p>
<p>&nbsp;</p>
<form name=&quot;form1&quot; >
<input type=&quot;text&quot; name=&quot;screen_width&quot;>
</form>
<p>&nbsp;


</p>
</body>
</html>
 
I think what's happening here is it's reading the javascript before the form element has been rendered??

try sticking your script into a function, and then call it body onLoad like this:

<script language=&quot;JavaScript&quot;>
function fillMe(){
document.form1.screen_width.value = (window.screen.width);
}
</script>

<body bgcolor=&quot;#FFFFFF&quot; onLoad=&quot;fillMe();&quot;>
 
Thank you so much,
now the contact form on the site report the users:

screen height
screen width
IP address
Browser version
Windows version

Thank you very much. Have you checked out the site?

(its just been launched, any feedback would be cool)

I'm really a Flash/Director developer (
If there is anything I can help you with ever, please let me know.

Cheers,

Matt
 
This has been very helpful to me too, however I'm using an external browser detection script which parses down the appName and appVersion into short phrases, e.g. ie4, ie55, ns6 etc. I'm not sure how to pass these variables through a hidden field in a form.

Please could someone take a look and see what I could do to call the short phrases instead of getting the standard response of eg. Microsoft Internet Explorer, Windows NT. etc etc.

Thanks in advance,
Scooter

This is my code:
<head>
<script language=&quot;javascript&quot; SRC=&quot;JavaScript/browser.js&quot;></script>

This is the content of browser.js:

function Browser() {
var b=navigator.appName;
if (b==&quot;Netscape&quot;) this.b=&quot;ns&quot;;
else if ((b==&quot;Opera&quot;) || (navigator.userAgent.indexOf(&quot;Opera&quot;)>0)) this.b = &quot;opera&quot;;
else if (b==&quot;Microsoft Internet Explorer&quot;) this.b=&quot;ie&quot;;
if (!b) alert('Unidentified browser./nThis browser is not supported,');
this.version=navigator.appVersion;
this.v=parseInt(this.version);
this.ns=(this.b==&quot;ns&quot; && this.v>=4);
this.ns4=(this.b==&quot;ns&quot; && this.v==4);
this.ns6=(this.b==&quot;ns&quot; && this.v==5);
this.ie=(this.b==&quot;ie&quot; && this.v>=4);
this.ie4=(this.version.indexOf('MSIE 4')>0);
this.ie5=(this.version.indexOf('MSIE 5')>0);
this.ie55=(this.version.indexOf('MSIE 5.5')>0);
this.opera=(this.b==&quot;opera&quot;);
this.dom=(document.createElement && document.appendChild && document.getElementsByTagName)?true:false;
this.def=(this.ie||this.dom); // most used browsers, for faster if loops
var ua=navigator.userAgent.toLowerCase();
if (ua.indexOf(&quot;win&quot;)>-1) this.platform=&quot;win32&quot;;
else if (ua.indexOf(&quot;mac&quot;)>-1) this.platform=&quot;mac&quot;;
else this.platform=&quot;other&quot;;
}
is = new Browser();

function writebrowserdetails()
{
document.login.browsertype.value = (Browser);
document.login.browserversion.value = (Browser);
}
</head>

<body onload=&quot;writebrowserdetails();&quot;>

<form name=&quot;login&quot;>
<input type=&quot;hidden&quot; name=&quot;browsertype&quot;>
<input type=&quot;hidden&quot; name=&quot;browserversion&quot;>
</form>

</body>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top