1

I have an HTML page with input text box.Now I need to pass that value to another html page and read that value.

My 1st HTML page code:

  <!DOCTYPE html>
  <html>
  <head>
 <form target="_blank" action="indextable.html" method="GET"> 

 <input type="managerid" class="form-control" id="ManagerId" type ="text" 
  autocomplete="off"  maxlength="8" onkeyup="alphanumOnly(this)" 
   placeholder="ManagerId"></input>

 <button id="submit" class="btn btn-primary" style="margin-top: 3px;"  
 this.disabled = true;  >Submit</button>

 <input type="reset" class="btn btn-primary" style="margin-top: 3px;" 
 value="Reset" onClick="window.location.reload()"></input>   
 </form>

My 2nd HTML page code:

     <!DOCTYPE html>
     <html>
     <head>
     <script src="index.js" type="text/javascript"></script>
     <body>
     <script type="text/javascript">
     getReporteeList();      //This is javascript function which is there 
                                    in the index.js file
     </script>
     </body>
     ...

When I do like this it is giving me an error as :

 Uncaught TypeError: Cannot read property 'value' of null
at getReporteeList.

Please let me know where I am going wrong.if possible please provide some sample code.Thanks in advance.

My index.js Code

        function alphanumOnly(input){
        var regex = /[^a-zA-Z0-9]/gi;
        input.value = input.value.replace(regex, "");
         }
        var name = document.getElementById('ManagerId').value;
        function getReporteeList() {
        var name = document.getElementById('ManagerId').value;
        console.log(name); 
        $.ajax({
      url:'http://localhost:8088/JirasTrackingApp/
      reporter/Reportees/ReporteeList/'+ $("#ManagerId").val(),
      type:'GET',
      "crossDomain": true,
      beforeSend: function(xhr){
     },

      dataType: 'json',
      success: function(result){   
         var end = new Date().getTime();
         var dur = end - start;
         console.log("millisecs passed",dur);   
           var  size = result.length;
           var content = '';
           var number = 1;
           if(size>0){
            document.getElementById('table').style.display="block";
           $.each(result,function(key,value){
               var num    = number++;
               content += '<tbody>';
               content += '<tr>';
               content += '<td>'+num+'</td>';
               content += '<td>'+value.Name+'</td>';
               content += '<td>'+value.UserId.toUpperCase()+'</td>';
               content += '<td>'+'<a href="#" onclick ="getJira(\'' + value.UserId + '\')">'+value.count+'</a>'+'</td>';
               content += '</tr>';
               content += '<tbody>';
           });

           $('#employee_table').append(content);

        }   
           else{
             alert("Please enter a Valid Associate Id");
         }
         },
        //error: function(result){
            error:function(jqXHR,exception){
               // alert("Invalid input");
               console.log(jqXHR);
               var msg='';
               if (jqXHR.status === "ERR_CONNECTION_REFUSED") {
                msg = 'Connection time out error.';
                alert(msg);
               }
               if (jqXHR.status == 500) {
                //msg = 'Please enter an valid input';
                alert("Please enter an valid input"+ "\n" + "The input must be started with 2 charactes"+
                "\n" + "Followed by 6 digits");
        }
    }

 });
Ramya
  • 49
  • 6

1 Answers1

1

Your fields need to have name attributes to pass values as the id will not do this.

The javascript DOM element selectors (document.getElementById('ManagerId').value, etc.) in index.js are looking for elements on page 2 that don't appear to exist. You'll have to do a little more to actually pull the the parameters from the URL using window.location.search(). See: How to obtain the query string from the current URL with JavaScript?

tshimkus
  • 1,173
  • 2
  • 17
  • 24