?
Solved

How to find this value

Posted on 2011-09-12
4
Medium Priority
?
209 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 82

Accepted Solution

by:
hielo earned 1000 total points
ID: 36525728
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
ID: 36525779
>>                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
ID: 36525807
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
ID: 36525815
I added "pgNo=" when I tested your script :)

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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
This article discusses how to implement server side field validation and display customized error messages to the client.
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…
Suggested Courses

765 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