homepage Welcome to WebmasterWorld Guest from 50.19.33.5
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor
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
tesla




msg:1487314
 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:

<td><form>
<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>

 

txbakers




msg:1487315
 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:

<script>
var res="";
function screenwidth() {
res = screen.availWidth;
document.Form1.SW.value= res;
}
</script>

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

Give that a try.

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

tesla




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

Txbakers,

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.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved