homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

Basic Javascript - Help!
Can't get javascript variable into Form

10+ Year Member

Msg#: 107 posted 2:34 am on May 9, 2002 (gmt 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>



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

Msg#: 107 posted 3:47 am on May 9, 2002 (gmt 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


10+ Year Member

Msg#: 107 posted 4:14 am on May 9, 2002 (gmt 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.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved