Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
| Search | Today's Posts | Mark Forums Read
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old May 28th, 2005, 05:05 AM
Authorized User
 
Join Date: Jul 2003
Location: , , .
Posts: 62
Thanks: 0
Thanked 0 Times in 0 Posts
Default Where is wrong of my alert statement?

I have a question about my javascript,I want to show the value of hidden by using alert(document.abcd.value),but when I run the html,I find it don't show the the hidden value,why? How to modify it?
My code is follows:

<html>
<head>
<script language="JavaScript">
alert(document.abcd.value);
</script>
</head>
<body>
<input type="hidden" name="abcd" value="11">
</body>
</html>

  #2 (permalink)  
Old May 28th, 2005, 05:12 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

When the page loads, it first hits the alert statement in the head section. At that point, the rest of the page hasn't loaded, so document.abcd doesn't exist yet.

Move your alert to the onload of the page that fires *after* the page has completed loading. You also need to wrap your control in a <form> tag and then reference it by its name:

<body onload="alert(document.frmTest.abcd.value);">
<form name="frmTest">
  <input type="hidden" name="abcd" value="11">
</form>
</body>

HtH,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Reverence by Faithless (Track 1 from the album: Reverence) What's This?


Similar Threads
Thread Thread Starter Forum Replies Last Post
alert darkhalf Javascript 3 November 18th, 2005 12:56 PM
What is wrong with this insert statement? method SQL Server 2000 13 April 27th, 2005 11:46 PM
What's wrong with this statement ? levinll SQL Language 4 April 29th, 2004 08:41 PM
What's wrong with this SQL Statement dc925 ADO.NET 4 January 23rd, 2004 11:27 AM
What's wrong with my SQL statement? kaz VS.NET 2002/2003 1 December 11th, 2003 09:21 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.