"Error message: The function is not defined in Firefox, IE, and

DoRowApp function works in Chrome, but is not defined in FF, IE, and Opera.

function DoRowApp(id) {
document.getElementById('ANSWER.TTQ.MENSYS.1.').value = id;
document.getElementById('ANSWER.TTQ.MENSYS.2.').click();
return true;}

This is the html code:

<a target="_blank" href="javascript:DoRowApp("_40558067");" title="Application Form"><img border="0"></a> 

This html snippet is generated from an xml source:

<cell>Application Form^javascript:DoRowApp("'||edit.mhd_code||'");^_blank</cell></row>

Any assistance on this issue would be greatly appreciated.

The following function works without any issues:

function DoRow(id) {
'use strict';
var LowerBound, UpperBound, StartAppNo, BaseAppNo, i;
LowerBound = mygrid.getRowIndex(id) - 25;
UpperBound = mygrid.getRowIndex(id) + 100;
StartAppNo = 25;
BaseAppNo  = 0;
mygrid.selectRowById(id, true, true, false);
localStorage.clear();
if (mygrid.getRowIndex(id) - 25 > 0) {
    StartAppNo =  25;
}
else {
        StartAppNo =  mygrid.getRowIndex(id);
    }
localStorage.setItem("9999", StartAppNo);
if (LowerBound < 0) {LowerBound = 0; }
for (i = LowerBound; i <= UpperBound; i++) {
    if (mygrid.getRowId(i)) {
        localStorage.setItem(BaseAppNo, mygrid.getRowId(i));
        BaseAppNo++;
    }
}
document.getElementById('ANSWER.TTQ.MENSYS.1.').value = id;
document.getElementById('ANSWER.TTQ.MENSYS.2.').click();
return true;}

The corresponding HTML for this function is:

<a target="_blank" href="javascript:DoRow("_40558067");" title="Application Form"><img border="0"></a>

Answer №1

I suggest removing the javaScript from your xml:

<cell>Application Form^'||edit.mhd_code||'</cell>

Alternatively, you can use this:

<cell rowId="'||edit.mhd_code||'">Application Form</cell>

This will generate the following HTML:

<a href="#" class="RowButton" data-rowId="_40558067" title="Application Form"><img border="0"></a>

You can now add a generic event handler in javaScript:

function DoRowApp (rowId) { /**/ }

// Simplified onLoad
window.onload = function () {

    // Enumerate all elements with class="RowButton"
    var rowButtons = document.getElementByClassName("RowButton");
    for (var i = 0; i < rowButtons.length; i++) {

        // Closure for i and rowButton
        (function (i, rowButton) {

            // Get the data-rowId attribute
            var rowId = rowButton.getAttribute("data-rowId");

            // Simplified addEventHandlerListener
            rowButton.onclick = function () {

                // Call your function
                DoRowApp(rowId);

                // Return false to prevent a href
                return false;
            };

        })(i, rowButton[i]); 
    }
};

I don't see where you are "opening" another webpage; in javaScript redirecting to another page is

window.location.href = "url";

To ensure it's the top-most frame, use

window.top.location.href = "url";

To open a new window, use window.open

window.open(url, "_blank");

Further readings

  • $(document).ready equivalent without jQuery
  • How can I get HTML elements by class in JavaScript?
  • How to redirect to another webpage in JavaScript/jQuery?
  • When and why to 'return false' in JavaScript?
  • addEventListener vs onclick

It is highly recommended to use jQuery for writing cross-browser javascript code. For beginners, avoid using w3schools and read more on . Better resources include

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Encountering issues with the phaser framework while setting up a server on xampp, faced with errors in javascript and html

Recently, I've been working on a game using Phaser and encountered some issues while trying to run the code in XAMPP. The game's base is located at htdocs/itw/test.html, with the necessary pngs and json file stored in htdocs/itw/assets/. The pngs ...

Strategies for eliminating _next folder from file path within the build directory of Next Js

Is there a way to eliminate "_next" from the path in the build folder for Next Js version 13.2.4? For reference, here is an example: We would greatly appreciate any assistance on this matter. ...

Shorten certain text in Vuetify

Here's an example of a basic select component in Vuetify: <v-select :items="selectablePlaces" :label="$t('placeLabel')" v-model="placeId" required ></v-select> I'm looking to apply a specific style to all selec ...

Transform the value of Material-UI DatePicker to seconds

I am trying to figure out how to convert the value from a React Material-Ui datepicker, which currently looks like this: 2021-05-26T01:30, into seconds. Any suggestions on how I can achieve this? PS: My goal is to create a schedule SMS module. Therefore, ...

Accessing data from a live database in a randomized sequence

When retrieving items from a database, there is often a common code pattern that looks like this: const [dataRcdArray, setDataRcdArray] = useState<never[]>([]); ..... snapshot.forEach((child:IteratedDataSnapshot) => { setDataRcdArray(arr ...

Ways to switch classes within a loop of elements in vue.js

I'm just starting to learn vue.js and I'm working on a list of items: <div class="jokes" v-for="joke in jokes"> <strong>{{joke.body}}</strong> <small>{{joke.upvotes}}</small> <button v-on:click="upvot ...

Encountering a 404 error while attempting to establish a connection between Express and React

My attempt to make a simple API request for bitcoin values is encountering some issues. When I enter in my Chrome browser, I receive a "Cannot Get /" message with a 404 error in the dev tools stating "GET 404 (Not Found)". However, when I visit , I succ ...

Node.js server only supports cross-origin requests for protocol schemes when working with an Angular front end

Struggling to configure CORS on a local site hosting a Node.js server and an Angular client. Encountering the following error: Access to XMLHttpRequest at 'localhost:3000/api/v1/users' from origin 'http://localhost:4200' has been bl ...

Automating the selection of a drop down based on a condition in Angular 2: A step-by-step guide

I'm facing an issue with a drop-down menu where no default value is selected. On my homepage, I need to automatically select an option based on query parameters. I've attempted various methods but none have been successful. Below is the code snip ...

Storing images in MongoDB using React.js

I'm currently facing an issue with uploading an image file from the client side to MongoDB. To achieve this, I am utilizing an Express server along with 'multer' and 'sharp' for image uploading. On the client side, I have a CRA a ...

Ways to retrieve a variable from outside of a function

I am in need of sending the following batch data to the database, but I am facing difficulties in including the course_id along with the batchData. Currently, I am retrieving the course_id from another service that fetches data from a course table. I am ...

When passing an object to a function inside a promise.then, Typescript may generate an error indicating that the object could

Snippet of code below is extracted from a request controller function. Goal The aim was to generate various notifications based on the paths that are modified. let farmerToUpdate = await FarmerModel.findById(farmerId) if (!farmerToUpdate) throw new cont ...

Transferring data between Promises and functions through variable passing

I am facing a challenge. I need to make two separate SOAP calls in order to retrieve two lists of vouchers, and then use these lists to perform some checks and other tasks. I have placed the two calls within different Promise functions because I want to in ...

Issue: setAllcategories function not found

Currently engaged in using Next.js and Sanity as a Headless CMS for the backend. In the code snippet below, I have created a Categories.js file in the components folder to fetch some data. My objective is to extract all the titles from the category Array. ...

Resize a group of images to match the parent's width and height dimensions

I am working with a div that contains variously-sized images and is nested inside a parent container. <div id="parentContainer"> <div id="boxToScale"> <img src="http://placehold.it/350x150" /> <img src="http://placehold.it/150 ...

What could be causing the jQuery click function to fail on following pages of the dataTable?

I created a code that generates a list of topics with delete and edit buttons within a datatable. Display.php <table data-toggle="table" class="table table-striped table-hover"> <thead> <tr> ...

Manipulate JSON objects in AngularJS by deleting or adding items

This JSON is currently in my possession: var videos = [ {"id":"9854", "time": 56}, {"id":"7859", "time": 29}, {"id":"8745", "time": 59} ]; If an item is missing from the JSON, I want to add it, but if it's already there, I want to remove ...

Masonry.js is working perfectly in Firefox, however, it is experiencing compatibility issues with Chrome and

Recently, I encountered a strange issue with Dessandro's Masonry.js library. It was working perfectly fine until it suddenly stopped functioning in Safari and Chrome (I haven't tested it on IE yet), while still working flawlessly in Firefox. Usua ...

Unveiling the mystery of extracting information from a string post serialization

When working with a form, I am using this jQuery code to fetch all the field values: var adtitletoshow = $("#form_data").serialize(); After alerting adtitletoshow, it displays something like this - &fomdata1=textone&fomdata2=texttwo&fomdat ...

Understanding variable scope in Node.js routing with Javascript

Consider the following code snippet: app.get("/location1", function(req, res){ async_function().then(result => { var str = result.toString(); }).catch(...)..... }); There are variables defined inside the .then() block of the asynchronous ...