Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

Basic Javascript - Help!

Can't get javascript variable into Form

2:34 am on May 9, 2002 (gmt 0)

Junior Member

10+ Year Member

joined:May 4, 2002
votes: 0

I'm trying to pass a javascript variable to a form. I'm failing. I'm doing something fundamentally wrong. I just want to pass the returned "screen width" to the Form so that I can ultimately pass it to the ss.htm page. Where have I gone wrong?

Here is the code:

<input type="hidden" name="Screen_Width" action="ss.htm" onload="screenwidth(this)"> <input type="image" src="f.gif"></td></form>

<script language="JavaScript"><!--
function screenwidth(res) {
res.value = screen.availWidth }
// --></script>

3:47 am on May 9, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member txbakers is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Sept 1, 2001
votes: 0

You've gone wrong in quite a few places.

The onLoad event doesn't apply to the <input> tag. You can put that in the <body> tag.

Also, you haven't declared "res" anywhere except within your function.

Here's what might work:

var res="";
function screenwidth() {
res = screen.availWidth;
document.Form1.SW.value= res;

<body onLoad="screenwidth()">
<form name="Form1">
<input type="text" name="SW" value="">

Give that a try.

There is an excellent javascript tutorial at www.w3Schools.com

4:14 am on May 9, 2002 (gmt 0)

Junior Member

10+ Year Member

joined:May 4, 2002
votes: 0


That did the trick. I have a book, but it is not very good at defining how javaScript interacts with forms. It does a good job defining all the methods. Part of my problem is that I don't have any code to look at as a reference. Your snipit of code will help a lot. Thanks.


Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members