Wrox Programmer Forums
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript 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
 
Old October 1st, 2004, 07:46 AM
Authorized User
 
Join Date: Aug 2003
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default Select/Option Problem

I've been trying to work with a simple select object. However, no matter how or when I try to call the object, I get a Null or No Object error. Following is the simplest sample where this problem occurs.

<head>
  <title></title>

<script language=JavaScript>

var myOptions = document.thisForm.mySelect;

</script>


</head>

<body bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">

<h1></h1>
<form name="thisForm">

  <select name="mySelect">
    <option value=0 selected>0</option>
    <option value=1>1</option>
    <option value=2>2</option>
  </select>

</form>


</body>


Any help is appreciated.

Best regards,
sabetec2
 
Old October 1st, 2004, 08:05 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

The select box is not yet created at the point you are trying to reference it, one way to get round this would be to place you code in a function & call it once the page has loaded...

Code:
<head>
  <title></title>

<script language=JavaScript>

function Init(){
    var myOptions = document.thisForm.mySelect;
}

</script>


</head>

<body onload="Init();" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">

<h1></h1>
<form name="thisForm">

  <select name="mySelect">
    <option value=0 selected>0</option>
    <option value=1>1</option>
    <option value=2>2</option>
  </select>

</form>


</body>
HTH,

Chris

 
Old October 4th, 2004, 03:32 PM
Authorized User
 
Join Date: Aug 2003
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks, Chris,
I guess all I can say is - "Duh!"

Pretty obvious once you pointed it out.

Thanks again,
sabertec2





Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with <SELECT <OPTION pegarr Classic ASP Basics 8 May 14th, 2008 09:49 AM
wrap a select option nerssi HTML Code Clinic 0 June 16th, 2007 07:43 AM
disable Select option Dj Kat HTML Code Clinic 2 March 10th, 2006 04:03 AM
javascript validation for select option anshul Javascript How-To 2 January 4th, 2005 12:31 AM
Getting select option name not value mildge Javascript How-To 2 April 5th, 2004 10:20 PM





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