Welcome to WebmasterWorld Guest from 23.20.241.155

Forum Moderators: open

Message Too Old, No Replies

Help with Javascript/CGI

updating another drop down list base on group

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

10+ Year Member



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.

Mei

====================================================
<: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
}

}
}
//-->
</script>
<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>

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

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

WebmasterWorld Senior Member blobfisk is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Welcome to WebmasterWorld, mei_mei!

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

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

10+ Year Member



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.

Mei

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

WebmasterWorld Senior Member blobfisk is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Could you dynamically create a JavaScript array with the information from your CGI array?
3:38 pm on Jun 26, 2003 (gmt 0)

10+ Year Member



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

Thanks a lot for your hint! :D

Mei

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

10+ Year Member



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

Mei

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

WebmasterWorld Senior Member blobfisk is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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)

10+ Year Member



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

WebmasterWorld Senior Member 10+ Year Member



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.

Shawn

 

Featured Threads

Hot Threads This Week

Hot Threads This Month