Solved

How to find this value

Posted on 2011-09-12
4
203 Views
Last Modified: 2012-05-12
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

0
Comment
Question by:davidw88
  • 2
  • 2
4 Comments
 
LVL 82

Accepted Solution

by:
hielo earned 250 total points
Comment Utility
try:
function submitPage(box){
                var pgNo = '';
                if( box.selectedIndex > -1 )
                  box.options[box.selectedIndex].value;

                location.href = "auth_token.htm?pgNo="+ pgNo + "&cb="+(new Date()).valueOf();
        }

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

   <form name="accountreport">                            
         <select id="pageBox" name="pageBox" onchange="submitPage(this);">
             <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>

If the above does not work, please open your page in a browser and then extract the browser's source code and post it here so we can see the HTML code that your server script is actually generating.

Open in new window

0
 
LVL 82

Expert Comment

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

Author Comment

by:davidw88
Comment Utility
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.

0
 

Author Comment

by:davidw88
Comment Utility
I added "pgNo=" when I tested your script :)

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

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now