Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to find this value

Posted on 2011-09-12
4
Medium Priority
?
212 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
This article discusses how to create an extensible mechanism for linked drop downs.
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…

610 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