Solved

How to find this value

Posted on 2011-09-12
4
207 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 250 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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

736 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