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 May 20th, 2004, 11:38 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Well, you know what they say: if it ain't broken, don't fix it ;) Glad it's working.

However, you can optimize your code a bit. If all the setChecked* functions do is set the required item, you can make the function dynamic, so you only need one function instead of 20. Instead of passing in just the ID of the control, you can also pass in the indices of the array:
Code:
function setChecked(selvalue, first, second)
{
    if(ID[first][second] == 'Y')
    {
        document.getElementById(selvalue).selectedIndex = 0;
    }
    else
    {
        document.getElementById(selvalue).selectedIndex = 1;
    }
}
This way, you only need one method that you can call with different parameters:
Code:
onLoad="setChecked('opt3308', 0, 0);setChecked('opt3326', 0, 1);setChecked('opt3320', 1, 1); etc etc
I just made up the numbers I am passing to setChecked, but I am sure you get the idea.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Soulfly (Universal Spirit Mix) by Soulfly (Track 16 from the album: Primitive) What's This?
 
Old May 20th, 2004, 11:43 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

And if you REALLY want to save space, rename the function to c() or something :D

Snib

<><
 
Old May 20th, 2004, 01:39 PM
Friend of Wrox
 
Join Date: Apr 2004
Posts: 121
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Folks,

There is very little difference in each checked_ function. Here is one of them...

<script language="JavaScript">
function setCheckeda(selvalue)
{
    if(ID[0][2] == 'Y')
    {
        document.getElementById(selvalue).selectedIndex = 0;
    }
    else
    {
        document.getElementById(selvalue).selectedIndex = 1;
    }
}
</script>

The only difference is the ID array numbers change in each function because each yes/no select menu needs to be tied to a specific ID[#][#]. If there is a smoother. more dynamic way to do that...great. Let me know. But basically I have an array with like 18 values in each and each one needs to be tied to a select menu. By the way, this is a page that will be pulled locally...not across the web. It is not asp, which I would prefer, but unfortunately...it is not. And all the comment tags and mess was put in there by another user via dreamweaver who is a designer not a programmer. I just want to make the code work as smoothly as possible. Thanks for the assist.

Clay Hess
 
Old May 20th, 2004, 01:53 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Clay,

If I understand your last post correctly, I think I already posted the "smoother, more dynamic way". Your setChecked should accept the numbers to index your array as parameters. Your onload code can then pass the required numbers into the setChecked method.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old May 20th, 2004, 03:10 PM
Friend of Wrox
 
Join Date: Apr 2004
Posts: 121
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Imar,

Thanks a lot for the suggestion! That did make it smoother. I went down to one function and placed that in the head and then just passed the array variables. Again...thanks for the assist!

Clay Hess
 
Old December 9th, 2005, 11:06 AM
Registered User
 
Join Date: Dec 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,
I was getting the same error. It seems that it refers to the use of brackets.
onload = setChecked;
rather than
onload = setChecked('opt3308');
should eliminate the error. Try passing the
'opt3308'
some other way perhaps using a global variable.
This is to help out anyone else who might end up here with the same problem.






Similar Threads
Thread Thread Starter Forum Replies Last Post
operation not yet implemented RichardMaly Crystal Reports 11 January 8th, 2013 02:22 PM
Handling isLockedOut isn't implemented Joe@Tulsa BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 1 April 3rd, 2007 04:06 AM
Ok datagrid implemented however macupryk General .NET 1 October 7th, 2004 11:29 AM





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