Sharing data between functions in JavaScript allows for more flexible and interdependent code structure

After invoking the Showmenu() JavaScript function from C# and passing a variable to it, there is a need to utilize this variable in another JavaScript function.

 <script type="text/javascript" >
 var strmenu;
 function ShowMenu(strmenu) {
 alert(strmenu); 
 }
 alert(strmenu);   
 ddsmoothmenu.init({
 mainmenuid: strmenu,  
 orientation: 'h',  
 classname: 'ddsmoothmenu',               
 contentsource: "markup")}
 </script>

The invocation of ShowMenu(strmenu) function in C# looks like this:

menu_Sysadmin.Attributes.Add("OnClick", "javascript:return ShowMenu('sysadmin')");

The goal is to use strmenu from showmenu() as a parameter in ddsmoothmenu.init(). While the value is displayed through an alert, attempts to make strmenu global have been unsuccessful.

Answer №1

The parameter strmenu in your code snippet is causing the global variable to be hidden. To resolve this issue, you will need to rename either the global variable or the function parameter and then assign a value within the function.

var menu;
function DisplayMenu(strmenu) {
    menu = strmenu;
}

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

The setter function for a boolean value in React's useState hook is malfunctioning

I encountered an issue while trying to update a state value using its setter from the useState hook. Surprisingly, the same setter worked perfectly in a different function where it set the value to true. To confirm that the function call was correct, I te ...

Detecting errors on the client side with JSON payload in Next.js and a personalized server

Working with Next.js and a custom Express server, I've encountered an issue regarding basic API error handling. I have set up a simple error handling middleware that looks like this: app.use((err, req, res) => { res.status(400).send(message); ...

Attempting to pass a limit argument to a query in urql, Strapi, and Next JS for the Query.posts field has resulted in a combination of errors including graphQLErrors

I need help figuring out how to pass a variable for the limit parameter in my GraphQL query. I am currently working with urql, Strapi, and its GraphQL plugin in a Next.js application. My goal is to introduce a variable for the limit to restrict the number ...

provide the key and id to a node.js module

Currently, I am utilizing the Express framework to establish a module for handling requests to a third-party API. This particular API necessitates an ID and key to be transmitted. Rather than embedding these credentials directly into the module, I prefer ...

When the mouse is moved, display a rectangle on the canvas

I am having an issue with drawing a rectangle on canvas. The code below works fine, except that the path of the rectangle is not visible while the mouse is moving. It only appears when I release the mouse button. Any assistance would be greatly appreciate ...

Convert JavaScript objects to strings with JSON strings already included as values

Although this question may seem like a duplicate, I have not been able to find the answer. My issue is with stringifying a JavaScript object that contains JSON strings as values. Here is an example: var obj = {id:1, options:"{\"code\":3,\" ...

Error message: It seems the spatial reference for this ESRI object is missing

Currently, I am utilizing Esri GIS to load the center location from an address. However, I am encountering an issue as I am using a geocoder from Google to obtain longitude and latitude, which is resulting in the following error message: TypeError: this.s ...

Instructions for attaching an event listener to a Threejs Mesh Object with the help of threex dom events

var domEvents = new THREEx.DomEvents(camera, view.domElement); var div = document.createElement( 'div' ); div.setAttribute('data-remove','mesh1'); div.className = 'close-me'; var label = new THREE.CSS2DObje ...

Prevent unnecessary clicks with Vue.js

In my vue.js application, there is a feature to remove items. The following code snippet shows the div element: <div class="ride-delete" @click="delete"> <p>Delete</p> </div> This is the function used to handle the click ...

Adding new options to a multi-select dropdown in Vue.js when fetching data using an

Greetings! I've been utilizing a modified wrapper to manage a multiple select for vue.js. My goal is to change the value of 'this' inside the vue component. Below is the snippet of my code. <select2-multiple :options="car_options" v-mode ...

Can you explain the functions of this "malicious" JavaScript code?

I came across this piece of code on a website that labeled it as "malicious" javascript. Given my limited knowledge of javascript and the potential risks involved in trying out the code on my own site, I was hoping someone here might be able to shed some l ...

The submission feature for the textarea in Javascript is not functioning properly

As someone who is new to frontend development, I am currently facing a challenge with debugging JavaScript code that involves making changes to the content of a textarea. Despite my efforts to debug using the browser console, I have yet to identify why it ...

Using CSS to design a table-like structure with rows that span multiple columns

I am trying to generate a table dynamically using CSS and a JSON array. For example: In the code snippet provided, I have assigned a class of 'spannedrow' to span certain cells in the table, although the class is not defined yet. This is just ...

Object representing a dictionary of words and their meanings

Is it possible to loop through a dictionary that holds objects and enum types? foreach(Dictionary<someObject, enumType> myDic in myObjects) { if(enumType.myType == enumType.Type) { perform a specific action here... } } ...

How to Add Pagination Feature in ASP.Net Gridview Component

I am facing an issue with my gridview that is bound on page load and I have implemented insert using the footer row technique. Recently, I tried adding pagination to the same gridview. Although there are no errors, when I change the page in the dropdown ...

Establish a Zebra DataList Chart

My first task is to connect a Table from the database so that each row is editable. After some research, I settled on using the DataList due to its <EditItemTemplate> property, which the repeater lacks. To create a Zebra table, I crafted a CSS class ...

Selecting objects within a small three.js view

I am able to showcase an entire page filled with graphical elements using three.js and can even select objects by clicking on them. However, when attempting to display three.js graphics in a small viewport within an HTML page, issues arise. In order to ca ...

What is the best way to utilize this resulting value as an input?

I am trying to generate a random number using math.random and use that value in the following script: let bday = Math.floor( Math.random() * (30 - 1 + 1) + 1 ); await test.page.select('select[name="day_select"]',bday); However, I am ...

Tips for integrating google's api.js file into my vue application

Currently, I am in the process of integrating Google Calendar into my Vue project. The steps I am following can be found at this link. Additionally, I came across an example code snippet at this URL. This is how my Vue file looks: <template> <d ...

updating the v-model in Vue.js datepicker retains the previously set value while setting a new date

When using the template, the endDate updates as expected. However, there seems to be an issue when the filtersChanged method is called with the @selected attribute - the updated value is not the new one but rather the previously set value. <template&g ...