Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7947075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:19:44+00:00 2026-06-04T01:19:44+00:00

I have the below java script function in which I want to redirect the

  • 0

I have the below java script function in which I want to redirect the page to another page. I verified that ‘Got’ message is shown by the alert function. So, the function is invoked properly. However, the page redirection with window.location.href does not work. Moreover, the alert function that prints the content of option, vDaeId, dgpId does not executed (I dont see a pop up in the browser). Could you please tell me what’s wrong with this piece of code? Thanks. I am using firefox btw.

        function goToPMDisplayer(){
            alert('Got '); 
            var option=document.getElementById("D1").value;
            var vDaeId=document.getElementById("D2").value;
            var dgpId=document.getElementById("dgpids").value;
            var str= option + " "+ vDaeId + " "+ dgpId
            alert(str); 
            window.location.href="display.jsp?option="+option + "&vdaeid=" + vDaeId + "&dgpid=" + dgpId

        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T01:19:46+00:00Added an answer on June 4, 2026 at 1:19 am

    Moreover, the alert function that prints the content of option, vDaeId, dgpId does not executed (I dont see a pop up in the browser).

    That tells us that the code is failing by throwing an exception. My guess would be that you don’t have at least one of the elements you’re relying on having (D1, D2, or dgpids). So document.getElementById returns null, and when you try to access .value on it, you get an exception.

    Note that the strings you use with getElementById must be id values, not names. So you must have id="D1" on one element, id="D2" on another, and id="dgpids" on another. Also note that id values can be case-sensitive, and that they must be unique on the page. (Most browsers will give you the first one in document order if you mess up that last rule, but…)

    I assume that you’re not calling goToPMDisplayer until the page is fully loaded, but if you’re calling it during page load, make sure you’re not calling it until after the elements exist (e.g., put the call to it lower in the document than the elements).


    For problems like this, alert-style debugging went out some years ago. Here in 2012, we use proper debuggers. There’s one built into all major browsers these days, even IE. You can set break points, walk through code, inspect the current state of the DOM… In short, no need to fumble about in the dark; you can shine light on what’s happening.


    In a comment on the question, you’ve said

    I verified that all ements exist.

    With all due respect, I just don’t see how that can be. I suspect the id values are slightly different, or that they don’t have id values at all, but rather they have name values.

    Here’s a complete, working example: Live copy | source

    <!DOCTYPE html>
    <html>
    <head>
    <script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
    <meta charset=utf-8 />
    <title>Test Page</title>
    <style>
      body {
        font-family: sans-serif;
      }
    </style>
    </head>
    <body>
      <input id="D1" value="valueOfD1">
      <input id="D2" value="valueOfD2">
      <input id="dgpids" value="valueOfdgpids">
      <br><input id="theButton" type="button" value="Click Me">
      <script>
      function goToPMDisplayer(){
          alert('Got '); 
          var option=document.getElementById("D1").value;
          var vDaeId=document.getElementById("D2").value;
          var dgpId=document.getElementById("dgpids").value;
          var str= option + " "+ vDaeId + " "+ dgpId
          alert(str); 
          var loc = "display.jsp?option="+option + "&vdaeid=" + vDaeId + "&dgpid=" + dgpId
          alert("loc = " + loc);
    
      }
      document.getElementById("theButton").onclick = goToPMDisplayer;
      </script>
    </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have Javascript as below: <script type="text/javascript" language="javascript"> function redirectToPrevious(abcURL) { window.location.replace(abcURL); } function
I have a java file Test.java (below) which uses Guava's HashMultiMap (downloaded from http://code.google.com/p/guava-libraries/
I have wrote the code below which was taken from Java How to program
I have below a javascript function which gets called on click of two separate
Below I have a Json function and some php code which it retrieves. JavaScript
I have radGrid in .ascx page in which I want to find the control
Continuous JavaScript Scroller I have below script which is working on next and previous
Alrighty so below I have this script doing exactly what I want; I'm using
I have a ajax function as below <script type=text/javascript> $(document).ready(function () { var timer,
I have a HTML page in which I have a button; pressing that button

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.