homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

Help with Javascript/CGI
updating another drop down list base on group

 1:23 pm on Jun 26, 2003 (gmt 0)

I have two drop down lists: one is a list of groups (e.g. Group A, Group B...), the other one is a list of names.

The task is to update the name list based on the group (e.g. names from group A would be shown in the name drop down list if Group A is selected). I wrote a cgi script to retrieve the name from the database. Names are stored in an array for each group.

Problem: I don't know how to update the name drop down list with Javascript.

(I know how to update a text field with document.form1.name.value = <new name> in the Javascript but not a drop down list).

The following are pieces of code from my HTML. Can anyone please help?

Thanks for your time.


<:Use CGI /cgibin/listName.cgi Namespace=List:>
<script language="JavaScript">
function getName(group)
if(group == "GROUP A")
var num = <:Var List/cnt_A:>;
for(var i = 0; i < num; i++)
update name drop down list with name array retrieved from database with the CGI script
else if(group == "GROUP B")
var num = <:Var List/cnt_B:>;
for(var i = 0; i < num; i++)
same as above

<form name="form1" method="post" action="">
<select name="group" onChange="getName(document.form1.group.value)">
<option value="">Select a group</option>
<option value="Group A">Group A</option>
<option value="Group B">Group B</option>
<option value="Group C">Group C</option>

<select name="name" class="text" i">
<option value="">Select the name</option>
<?for n=1 to <:Var List/cnt_A:>?>
<option value="<:Var List/name_A[#n#]:>"><:Var List/name_A[#n#]:></option>



 2:54 pm on Jun 26, 2003 (gmt 0)

Welcome to WebmasterWorld, mei_mei!

This was asked recently here [webmasterworld.com] - hope this helps!


 3:25 pm on Jun 26, 2003 (gmt 0)

Thank you BlobFisk,

I had a look at questions/answers you provide through the link. I actually tried with arrays before I posted my question. The problem is that I have more than 30 groups in the group drop down list and each group has around 50 names (or more to be added later). I am just wondering if there is a way to just update the name drop down list with the name array retrieved from CGI using Javascript.

Thanks again for your help.



 3:28 pm on Jun 26, 2003 (gmt 0)

Could you dynamically create a JavaScript array with the information from your CGI array?


 3:38 pm on Jun 26, 2003 (gmt 0)

This is actually a good point. I will have to try it tomorrow.

Thanks a lot for your hint! :D



 12:28 pm on Jun 27, 2003 (gmt 0)

Sorry, BlobFisk,

I just realized that I have problem to get the array value in the javascript when I tried to create the dynamic arrays. They are there when I use warn() to display them in CGI. Is my syntax correct?

for(var i = 1; i < num; i ++)
var text = <:Var List/name[#i#]:>;


Thanks for your time and help



 12:32 pm on Jun 27, 2003 (gmt 0)

I'm afraid, mei-mei, that I have no working knowledge of CGI/Perl programming at all!

But I'm sure someone here does! You Could check out the Perl and CGI Forum [webmasterworld.com].


 12:47 pm on Jun 27, 2003 (gmt 0)

Thanks BlobFisk.


 12:28 pm on Jun 28, 2003 (gmt 0)

Hi mei_mei

I see you originally posted to the perl/cgi forum, and it got moved... Not really surprising given that your original post realted to javascript... But now you are back to needing cgi help...

So what cgi language is it? It is not valid perl or php (No point in me suggesting where the syntax errors are, as it is just so far removed from them that my guess is it must be a different language ... unless there are some fancy constructs I don't know about ;)

So let us know what language it is, and there might be someone who knows enough about that language to help.


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.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved