473,410 Members | 1,950 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,410 software developers and data experts.

Function Not Defined in JavaScript

When I run my webapp Mozilla is telling me that addRowInnerHTML is undefined. This only occurs when I try to write the results on a different jsp. If I write the results on index.jsp I do not get this problem. Here is my .js file.

Expand|Select|Wrap|Line Numbers
  1. function makeHttpRequest(url, return_xml)
  2. {
  3.    var http_request = false;
  4.  
  5.    if (window.XMLHttpRequest) { // Mozilla, Safari,...
  6.        http_request = new XMLHttpRequest();
  7.        if (http_request.overrideMimeType) {
  8.            http_request.overrideMimeType('text/xml');
  9.        }
  10.    } else if (window.ActiveXObject) { // IE
  11.        try {
  12.            http_request = new ActiveXObject("Msxml2.XMLHTTP");
  13.        } catch (e) {
  14.            try {
  15.                http_request = new ActiveXObject("Microsoft.XMLHTTP");
  16.            } catch (e) {}
  17.        }
  18.    }
  19.  
  20.     var environment = document.foo.cboEnvironment.value;
  21.     alert(environment);
  22.     var tradeID = document.foo.txtTradeID.value;
  23.     alert(tradeID);
  24.     var locationType = document.foo.location.value;
  25.     alert(locationType);
  26.     //window.location = 'response.jsp'
  27.  
  28.  
  29.    if (!http_request) {
  30.        alert('Unfortunatelly you browser doesn\'t support this feature.');
  31.        return false;
  32.    }
  33.    http_request.onreadystatechange = function() {
  34.        if (http_request.readyState == 4) {
  35.            if (http_request.status == 200) {
  36.                if (return_xml) {
  37.                    eval(callback(http_request.responseXML)); 
  38.                } else {
  39.                    eval(callback(http_request.responseText)); 
  40.                }
  41.            } else {
  42.                alert('There was a problem with the request.(Code: ' + http_request.status + ')');
  43.            }
  44.        }
  45.    }
  46.  
  47.    http_request.open('post', url, true);
  48.    http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  49.    http_request.send('environment='+ environment+'&tradeID=' + tradeID + '&locationType=' + locationType);
  50. }
  51.  
  52.  
  53. function callback(responseText)
  54. {
  55.     var temp = new Array();
  56.     temp = responseText.split('\t');
  57.     alert(responseText);
  58.     if( !(responseText.indexOf('#')!=-1) ){
  59.         var row1 = null;
  60.         var row2 = null;
  61.         for(var i = 0; i < temp.length; i++){
  62.  
  63.             if(temp[i] == 'Location:'){
  64.                 row1 = temp[i + 1];
  65.             }
  66.             else if(temp[i] == 'Found:'){
  67.                 row2 = temp[i + 1];
  68.             }
  69.  
  70.             if(row1 != null && row2 != null){
  71.                 addRowInnerHTML('Results', row1, row2);
  72.                 row1 = null;
  73.                 row2 = null;
  74.             }
  75.  
  76.         }
  77.  
  78.         makeHttpRequest('./Process', false);
  79.     }
  80.     else{
  81.         alert('no more');
  82.     }
  83.  
  84. }
  85.  
  86. function addRowInnerHTML(tblId, row1, row2)
  87. {
  88.   var tblBody = document.getElementById(tblId).tBodies[0];
  89.   var newRow = tblBody.insertRow(-1);
  90.   var newCell0 = newRow.insertCell(0);
  91.   newCell0.innerHTML = row1;
  92.   var newCell1 = newRow.insertCell(1);
  93.   newCell1.innerHTML = row2;
  94. }
  95.  
  96. function submitTrade(url, return_xml){
  97.  
  98.     window.location = 'response.jsp';
  99.     makeHttpRequest(url, return_xml);
  100. }
  101.  
The alerts are there for debugging.

Thank you for all the help,
John
Aug 2 '07 #1
5 3127
acoder
16,027 Expert Mod 8TB
Welcome to TSDN!

What do you mean by 'different jsp'? If you're going to make an Ajax call, you're staying on the same page. If the table is not present on the page, then you're going to get errors.
Aug 2 '07 #2
Thank you for the reply,

I have an index.jsp and when i click submit i want to go to another jsp to display the results. Is this possible or should I just go to a .html file?

Thank you,
John
Aug 2 '07 #3
epots9
1,351 Expert 1GB
Thank you for the reply,

I have an index.jsp and when i click submit i want to go to another jsp to display the results. Is this possible or should I just go to a .html file?

Thank you,
John
it is possible, but if u go to another page u make the ajax call useless. since ur going to another page on the second page just get the parameters that are passed to it.
Aug 2 '07 #4
it is possible, but if u go to another page u make the ajax call useless. since ur going to another page on the second page just get the parameters that are passed to it.
Thank you for the response.

I guess I am not sure what you are talking about. How does it make the ajax call useless? What do you mean by just get the parameters that are passed to it?

Thank you,
John
Aug 2 '07 #5
acoder
16,027 Expert Mod 8TB
Thank you for the response.

I guess I am not sure what you are talking about. How does it make the ajax call useless? What do you mean by just get the parameters that are passed to it?

Thank you,
John
An ajax call is made on the same page to get a response from the server without refreshing the page.

Remember Ajax should not be used in every possible scenario. In your case, a normal form submit and the action jsp page (response.jsp) dealing with the submitted values is just what you need.
Aug 3 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Stephen Poley | last post by:
Apologies if this is a silly question, but Googling on the archive didn't produce any answers. I have a piece of inline Javascript which works as expected in IE 6, Opera 7, Mozilla and NN 4. In...
4
by: gf | last post by:
<script> function testme(testvar) { if (testvar=='1') { alert('testvar=1'); document.open(); document.write('This is just some text<br /><br />"); document.write('<a...
8
by: Falc2199 | last post by:
Hi, Does anyone know how to make this work? var sectionId = 5; repeat_section_sectionId(); function repeat_section_5(){ alert("firing"); }
18
by: marcokrechting | last post by:
Hi All, I have a rather complicated problem. I use following function to display a hyperlink: a="<"+"a href='"; b3="<"+"a href='http://nww."; L="</"+'a><br>'; function...
17
by: Matt Kruse | last post by:
Perl's map() function is a powerful shortcut to accomplish many "loop over an array and do X" operations. Below is a quick hack to simulate similar functionality. I've used it a few times and find...
1
by: Sylaris | last post by:
hi, i have a problem which recursion fits perfectly, however; after working with the base function (which has no errors and works correctly) the recursions return a "function not defined" error in...
26
by: Patient Guy | last post by:
The code below shows the familiar way of restricting a function to be a method of a constructed object: function aConstructor(arg) { if (typeof(arg) == "undefined") return (null);...
2
by: NightWalker | last post by:
Hi, I'm having a little trouble with a javascript function that I can't get to work but can't find the reason why. I have the folowing code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0...
3
pbmods
by: pbmods | last post by:
AN INTRODUCTION TO FUNCTION OBJECTS LEVEL: INTERMEDIATE PREREQS: OBJECTS You've seen it before. You're setting up an XMLHttpRequest call, and you need to execute a function when it returns, so...
6
by: JLupear | last post by:
I have written a code (a translation of my first one) that is not working. I did a user defined function that is used on 'onsubmit'. It should total the value from the form selections and...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.