Wrox Programmer Forums
| 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
 
Old January 24th, 2005, 02:21 AM
Registered User
 
Join Date: Jan 2005
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default is null or not an object

hi, i am getting an error 'document.forma3.myselect3 is null or not an object' i have many forms on the page and the first of which will not error but the rest error. this javascript is being called from an asp page.

<script language='javascript'>
function setOptions(chosen,theformnum){
    var ff = document.forms['forma' + theformnum].elements["tota" + theformnum];
    var ee = document.forms['forma' + theformnum].elements["hidercnt" + theformnum].value;
    ff.value = "$" + ee * chosen + ".00";
    }
</script>

for i = 1 to 6
<form name='forma<%=i%>' method='post'>
<select name="myselect<%=i%"> onchange="setOptions(document.form<%=i%>.myselect< %=i%>.options[document.form<%=i%>.myselect<%=i%>.selectedIndex].value,'<%=i%>');">
<option value='1'>1</option>
<option value='2'>2</option>
<option value='3'>3</option>
<option value='4'>4</option>
<option value='5'>5</option>
<option value='6'>6</option>
</select>
<input type='text' name='tota<%=i%>'>
<input type='hidden' name='hidercnt' value='10'>
</form>

i am passing to the setOptions() function the option selected and the form number which should tell the function which form and which textbox to populate, the first select box works just fine, but any of the other select boxes produce the error (even if the first select box i chose is not the first one on the page). Please help.
Jim
 
Old January 24th, 2005, 02:11 PM
Friend of Wrox
Points: 2,473, Level: 20
Points: 2,473, Level: 20 Points: 2,473, Level: 20 Points: 2,473, Level: 20
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2004
Location: India
Posts: 642
Thanks: 0
Thanked 43 Times in 42 Posts
Default

Please check the following code:

<script language='javascript'>
function setOptions(chosen,theformnum){

    var ff = eval('document.forma' + theformnum + '.tota' + theformnum + '');

   var ee = eval('document.forma' + theformnum + '.hidercnt' + theformnum + '.value');

    ff.value = "$" + ee * chosen + ".00";
    }
</script>

<%for i = 1 to 6%>
<form name='forma<%=i%>' method='post'>
<select name="myselect<%=i%>"
onchange="setOptions(document.forma<%=i%>.myselect <%=i%>.options[document.forma<%=i%>.myselect<%=i%>.selectedIndex].value,'<%=i%>');">
<option value='1'>1</option>
<option value='2'>2</option>
<option value='3'>3</option>
<option value='4'>4</option>
<option value='5'>5</option>
<option value='6'>6</option>
</select>
<input type='text' name='tota<%=i%>'>
<input type='hidden' name='hidercnt<%=i%>' value='10'>
</form>
<%next%>


Om Prakash




Similar Threads
Thread Thread Starter Forum Replies Last Post
'style' is null or not an object earhear Beginning PHP 0 December 4th, 2007 04:22 AM
null or not an object crmpicco Classic ASP Basics 0 July 4th, 2005 05:58 AM
null or not a object crmpicco Javascript How-To 5 March 22nd, 2005 10:48 AM
document null or not an object Adam H-W Javascript 2 April 22nd, 2004 05:59 AM





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