Link to home
Start Free TrialLog in
Avatar of davidw88
davidw88

asked on

How to find this value

Hi experts,

On a webpage there is a drop-down menu that has page numbers like 2, 3, 4. When a user chooses a number, the webpage is supposed to change to that page. However, the script that I have now does not work.

Any help?

Thanks so much.  
function submitPage(){

                var box = document.accountreport.pageBox;
                var pgNo = box.options[box.selectedIndex].value;

                document.location.href = "auth_token.htm?pgNo="+ pgNo;
        }

//-----------------------------------------
related part of jsp:

   <form name="accountreport">                            
         <select id="pageBox" name="pageBox" onChange="javascript:submitPage();">
             <c:forEach items="${pages}" var="page" varStatus="loop">
               <option value="<c:out value="${page}"/>" 
                   <c:if test="${page == param.pgNo}">SELECTED</c:if>><c:out value="${page}" />
               </option>
             </c:forEach>

         </select>
    </form>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>>                if( box.selectedIndex > -1 )
>>                  box.options[box.selectedIndex].value;
Should have been:
                if( box.selectedIndex > -1 )
                    pgNo=box.options[box.selectedIndex].value;
Avatar of davidw88
davidw88

ASKER

Thanks hielo! Your solution works perfect.


I have figured out why my old script did not work. It should be something like this:

             var boxObj = document.getElementById('pageBox');
             var pgNo  = boxObj.options[boxObj.selectedIndex].value;

this works.

I added "pgNo=" when I tested your script :)

Should have been:
                if( box.selectedIndex > -1 )
                    pgNo=box.options[box.selectedIndex].value;