Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    validate order of dynamic dropdown menu

    Hi I'm having trouble with my validating the arrangement of my item list. Here's the scenario. I have several categories. Under each category are items. These items can be re-arranged for displaying purposes. Example Category A may have apple, ornage, grapes. Categ B may have carrots, potato. The items are dynamically inserted using database. I need to validate that arrangement of the items per category. It seems that my getElementByID is not working when I use it in my dropdown menu.
    <%Rs = Select * from tblProducts Inner Join tblCategory ON tblCategory.ID=tbProducts.CategoryID order by CategoryID%>
    <table>
    <%do while not rs.eof%>
    <tr>
    <td><%=rs("CategoryName")%>
    <input name="categ_<%=categctr%>" type="hidden" value="<%=rs("categoryid")%>" id="categ_<%=categctr%>"> </td>
    <td><select name="rank_<%=listctr%>" class="catgrp_<%=categctr%>"
    id="rank_<%=listctr%>">
    <option value="0"></option>
    <%For ctr = 1 to ranklist%><!--if there are 3 items under this
    category, the dropdown menu will list 1,2,3 -->
    <option value="<%=ctr%>"><%=ctr%></option>
    <%Next%>
    </select>
    </td>
    <td><%=rs("ProductName")%></td>
    <%rs.movenext
    Wend%>

    javascrit part validation......
    function ValidateRank(){
    var categCount;
    var categval;
    var totalrankpercategory;
    var numRank;
    categCount = document.product.totalCategory.value; //total category count that will be used for looping
    for(categcounter=1; categcounter <= categCount; categcounter++)
    {
    //get the value of category
    categval = eval("document.product.categ_" + categcounter + ".value");
    alert ("The Category beind tested is Category ID= " + categval);
    //compare if rank belongs to category using class of dropdown menu. used alert only of testing if it works
    if("document.getElementById('totalrankpercateg_" + categval + "').className == 'totalrankpercateg_" + categval + "'")
    {
    // get totalrank per category
    totalrankpercategory = eval("document.product.totalrankpercateg_" + categval + ".value");
    for(x=1; x <= totalrankpercategory; x++)
    {
    if("document.getElementById('rank_" + x + "').className == 'catgrp_" +
    categval + "'")
    {
    numRank = eval("document.getElementById('rank_" + x
    + "').selectedIndex"); );<!--this is where im having difficulty. I dont get the right value that was seledted from the dropdown menu. -->

    alert ("Category ID = " + categval + ". Total Rank= " +
    totalrankpercategory + ". Rank List = " + numRank }
    }
    }

    }

  • #2
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    Do a view source and look at what the browser sees. You ASP code may be wrong or something.
    Javascript is case-sensitive, unlike VBScript.

    If you still don't see what's wrong, post only the browser code here (not the ASP). Use the code [ code ]
    and [ /code ]
    (no spaces) to enclose it so it's readable, okay?

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #3
    New Coder
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for your help! Yeah I got it. You're right I have not reconsidered that javascript is case sensitve unlike vbscript. Thanks!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •