Ignite the Function within FireFox

Why isn't Firefox able to interpret this code properly when it works fine in IE?

<%@ Language=VBScript %>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</HEAD>
<script type='text/javascript'>
function drvFunc(elem)
{
    var e = elem.name;
    var d = "document."
    var f = "frm";
    var str = d+"."+f+"."+e+".value;";
    alert(eval(str));
}
</script>
<BODY>
<form name=frm method=post>
<input type=button name=myButton id=myButton value='MyButton' onclick='drvFunc(this)'>
</form>
</BODY>
</HTML>

Answer №1

const greetingFunc = (element) => {
  console.log(element.value);
}

No need for dangerous eval() in this simple function...

Answer №2

There seems to be an issue with the concatenation of two periods in your code:

  1. let a = "apple."
  2. let b = a + "." + fruit...

As a result, your combined string reads: "apple..banana.orange;"

To fix this, simply remove one of the periods from your concatenation.

Answer №3

Modify

var d = "document."

to

var d = "document"

You are executing eval with "document..frm"

Answer №4

I am the original creator of this coding discussion. It seems like I may have not clearly explained the issue at hand.

function drvFunc(elem)
{
    **var e = elem.name;** <-- this causes an error in Firefox. 'e' is not initialized!! 
    var d = "document."
...
}

When working on a form, writing code like this usually functions without any issues in Internet Explorer...

<input type=button name=1stButton id=1stButton onclick='drvFunc(this)'>
<input type=button name=2ndButton id=2ndButton onclick='drvFunc(this)'>

... and then drvFunc might look something like this

function drvFunc(elem)
{

}

Answer №5

If you prefer, try this alternative approach:

<input type='button' name='2ndButton' id='2ndButton' onclick='actionFunction(this.id)'> 

function actionFunction(elementId){ 
   alert(document.getElementById(elementId).value); 
}

Answer №6

Make sure to enclose the attributes on your <input> tag in quotes, either single or double.

It seems that Firefox and IE may handle unquoted attributes differently:

In addition to adding quotes, remove the extra dot in "document." as suggested by others, and consider refactoring the drvFunc function to eliminate the use of eval.

Below is a snippet that functions correctly on Firefox 3:

<%@ Language=VBScript %>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<script type='text/javascript'>
function drvFunc(elem)
{
    alert(elem.value);
}
</script>
</HEAD>
<BODY>
<form name="frm" method="post">
<input type="button" name="myButton" id="myButton" value="MyButton" onclick="drvFunc(this)">
</form>
</BODY>
</HTML>

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

Ways to automatically scroll text inside a div based on the div's width

I currently have a div with a fixed width. My goal is to automatically scroll the text (left and right in a horizontal direction) within the div if the content exceeds the width of the div. How can I achieve this using CSS or jQuery? The class for the div ...

Struggling with making successful callback return statements

Having some difficulty skipping callbacks returns. Here is the query: Create a function named tap that takes an array called items and a callback function, cb. The callback function should be executed on the array, and then the array itself should be ret ...

Struggling to send data to child components in Vue: Received an object instead of the expected string value of "[object Object]"

My goal is to create a basic To-Do app where, upon clicking the button <b-button v-on:click="newItem" pill variant="primary">Add</b-button>, the input text is displayed below. To achieve this, I am using v-model in the input field (located in ...

Is there a way for my discord bot to notify me when a certain user is playing a particular game?

How can I set up my bot to automatically send a message when a specific user starts playing a specific game, like Left 4 Dead 2? I'm looking for a way to do this without using any commands. // Game Art Sender // if (message.channel.id === '57367 ...

Unexpected behavior when using ES6 import/export statements

I'm not entirely sure if this issue is related to react-native, but here are the versions I am using: "react-native": "0.46.4", "babel-preset-react-native": "2.1.0", // src/utils/a.js export default 'a file works!' // src/utils/b.js expor ...

react navigation not appearing

One challenge I've encountered is adding a react router link to the modal in my app. When clicking on the modal, the id doesn't immediately show in the url. The modal id only appears in the url after closing the modal. Additionally, if I reload t ...

Mapping a bar chart on a global scale

Are there any methods available to create bar charts on a world map? The world map could be depicted in a 3D view resembling a Globe or in a 2D format. It should also have the capability to zoom in at street level. Does anyone have suggestions or examples ...

Handling invalid JSON strings in controller functions with JavaScript and Node.js

Issue with Incorrect JSON Formatting in Node.js Controller Function Upon sending a JSON object via AJAX to a route in Node.js, the req.body data received in the controller function seems to be incorrectly formatted. What could be causing this issue? Java ...

Executing a custom Django view class method at a single URL path

I'm a newcomer to the world of Django and I am interested in managing my database using custom methods within the views file. For instance, I have written this code that I would like to execute with JavaScript: Js: $.ajax({ type: 'POST& ...

Verify the level of opacity in the image

I'm working on a website that allows users to upload PNG images and save them. However, before they can save the image, I need to check if it contains transparency. Is there a way to determine if an image is not 24-bit using JavaScript? <img id= ...

Executing React's useEffect hook twice

As I work on developing an API using express.js, I have implemented an authentication system utilizing JWT tokens for generating refresh and access tokens. During testing with Jest, Supertest, and Postman, everything appears to be functioning correctly. O ...

Where can variables be found within the scope?

Would it be possible to automatically identify all variables within a specific scope? For example: var localScope = function() { var var1 = "something"; var var2 = "else..."; console.log(LOCAL_SCOPE); }; and have LOCAL_SCOPE return an object ...

Dealing with Large JSON Strings in ASP.NET MVC Views

Large JSON Objects (approximately 1.5 MB) are received in Controller C1. They are then converted to strings and stored in a hidden label in View V1. The JSON data in V1 is utilized by parsing it in JavaScript J1. An occurrence of Out of Memory Excepti ...

Tips on setting up and managing configuration and registering tasks in Grunt

I've been working on a project that involves using grunt to process my Js and SASS files. The issue I'm facing is that every time I need to make a change, I have to run all the tasks in my gruntfile.js, even if it's just for one module or th ...

Issues with Subject.subscribe occurring beyond the constructor

If you're looking for a straightforward service, I've got just the thing for you. import { Injectable } from '@angular/core'; @Injectable({ providedIn: 'root' }) export class XmlService { items$: Subject<Item[]> = ...

JS receiving a reference to an undefined variable from Flask

I referenced this helpful post on Stack Overflow to transfer data from Flask to a JS file. Flask: @app.route('/') def home(): content = "Hello" return render_template('index.html', content=content) HTML <head> ...

Resource Jump.js could not be loaded

Although I am still new to NPM, I have mostly built websites without using it. Recently, I decided to implement smooth scroll using Jump.js. Initially, everything seemed to work well when I used the live server extension in VScode. However, once I uploade ...

Creating a ripple effect on a circle with CSS and HTML when it is clicked

Can anyone assist me in creating a wave effect around the circle when it is clicked? To better visualize what I am trying to achieve, you can view this GIF image. Appreciate your help in advance! ...

Attaching to directive parameters

I've been working on creating a draggable div with the ability to bind its location for further use. I'm aiming to have multiple draggable elements on the page. Currently, I've implemented a 'dragable' attribute directive that allo ...

MongoDB effortlessly integrates arrays into data schemas

I find myself in a puzzling situation without knowing the cause. Despite my efforts, I cannot seem to find any information on this strange issue. Therefore, I have turned to seek help here. //mongoDB data schema const dataSchema = mongoose.Schema({ use ...