»
 

Go Back   ResellerRatings Store Ratings > ResellerRatings Forums > Tech Support

Reply
 
LinkBack Thread Tools Display Modes
Old 04-30-2004, 01:16 PM   #1 (permalink)
Registered User
 
Tekk's Avatar
 
Join Date: Oct 2001
Location: SoCal
Posts: 1,122
Tekk is on a distinguished road
Help with javascript select box

For my class we're working on this weird little article updating web app using ASP. Each article that we can add to the database must have a main category and a sub category. Thats all fine and dandy but my problem is when a user wants to edit the article. Now the user should be able to edit any portion of the article (except the article date) and the same form that I use for adding articles is being used to edit an article, except when the edit link is pressed the form will be populated with the information of that specific article.

My problem is this: I can get the correct main category to load on the edit page for that article but i cant figure out a way to get the sub-category to load properly. Since the sub cat select box content always depended upon the user selecting a main cat (I have the main cat select box have an onChange="goSub(this)" parameter to fill the sub cat box) is there a way to use the same script so that on the edit page the sub cat box can be automatically changed to the correct category? Or should I write a new function?

Here's my javascript for filling the sub cat when the main cat box is changed:

Code:
<SCRIPT LANGUAGE="JavaScript">

function goSub(cat_no){
for (var i = document.addform.article_subcat.options.length; i >= 0; i--){
document.addform.article_subcat.options[i] = null;
}
if (cat_no.options[cat_no.selectedIndex].value==0){
document.addform.article_subcat.options[document.addform.article_subcat.options.length] = new Option('Select a Main Category','0');
}
if (cat_no.options[cat_no.selectedIndex].value==1){
document.addform.article_subcat.options[document.addform.article_subcat.options.length] = new Option('HTML','1');
document.addform.article_subcat.options[document.addform.article_subcat.options.length] = new Option('XHTML','2');
document.addform.article_subcat.options[document.addform.article_subcat.options.length] = new Option('XML','3');
}
if (cat_no.options[cat_no.selectedIndex].value==2){
document.addform.article_subcat.options[document.addform.article_subcat.options.length] = new Option('Classic ASP','1');
document.addform.article_subcat.options[document.addform.article_subcat.options.length] = new Option('ASP.NET','2');
}
if (cat_no.options[cat_no.selectedIndex].value==3){
document.addform.article_subcat.options[document.addform.article_subcat.options.length] = new Option('MySQL','1');
document.addform.article_subcat.options[document.addform.article_subcat.options.length] = new Option('Access','2');
document.addform.article_subcat.options[document.addform.article_subcat.options.length] = new Option('SQL_Server','3');
}
if (cat_no.options[cat_no.selectedIndex].value==4){
document.addform.article_subcat.options[document.addform.article_subcat.options.length] = new Option('Perl','1');
document.addform.article_subcat.options[document.addform.article_subcat.options.length] = new Option('Python','2');
}
}

</SCRIPT>

__________________
Im very explosive right now...BOOM! Very explosive.
Tekk is offline   Reply With Quote
Old 04-30-2004, 01:17 PM   #2 (permalink)
Registered User
 
Tekk's Avatar
 
Join Date: Oct 2001
Location: SoCal
Posts: 1,122
Tekk is on a distinguished road
The url for this is

http://hwang.cisdept.csupomona.edu/4.../mylibrary.asp

check it out if you so please Im more focused on the coding right now than the layout so I'll make it pretty later!
__________________
Im very explosive right now...BOOM! Very explosive.
Tekk is offline   Reply With Quote
Reply




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Most Active Discussions

Recent Discussions

All times are GMT -6. The time now is 07:20 PM.