Tips for distinguishing between submit() and other JavaScript functions, and understanding why submit() may not be functioning as expected

In the table, I have a list of users with "update" and "delete" links added at the end of each line. To enable this functionality, I implemented a JavaScript function that captures the user ID, sets another field to "true," and inserts these values into a form with two hidden fields. The function then triggers a submit operation to the ASP.NET server.

Upon checking, the submit operation works fine (verified using respons.write("-----"))

However, I am facing challenges in recognizing the post when activating submit() with JavaScript. I tried using the value of the hidden field, but it doesn't seem to capture it, leading to the skipping of the if statement...

Another issue I encountered during debugging is that the browser (IE9) throws an error when the submit() function is triggered...

The code for the list of users:

foreach(var row in db.Query(displayExperts,nameOfExpert))
                {
                <tr>
                    <td class="dispExpertActScreen">@row.ExpertID</td>
                    <td class="dispExpertActScreen">@row.name</td>
                    <td class="dispExpertActScreen">@row.password</td>
                    <td class="dispExpertActScreen">@row.allowBonds</td>
                    <td class="dispExpertActScreen">@row.allowStocks</td>
                    <td class="dispExpertActScreen">@row.allowExchangeTraded</td>
                    <td class="dispExpertActScreen">@row.allowMutualFund</td>
                     <td class="dispExpertActScreen"><a href="#" onclick="expertToDelete('@row.ExpertID') ;return false;" style="color: #b04e4e">update</a></td>
                    <td class="dispExpertActScreen"><a href="#" onclick="expertToDelete('@row.ExpertID') ;return false;" style="color: #b04e4e">delete</a></td>
                </tr>
                }

The form:

<form method="post" name="deleteExpert" style="font-size: medium; margin-top: 10%" dir="rtl">
    <input type="hidden" name="expertID" id="expertID" value="">
    <input type="hidden" name="txtJavascriptMode" id="txtJavascriptMode" value="">
</form> 

The JavaScript function:

<script>

    function expertToDelete(expertID) {

        document.getElementById('expertID').value = expertID;
        document.getElementById('txtJavascriptMode').value = 'true';
        document.getElementById('deleteExpert').submit();
    }

</script>

The ASP.NET code:

@{
    var db = Database.Open("MyProjectSite");
    var display="no";
    var displayExperts="";
    var nameOfExpert="";
    var category="";
     if(IsPost)
    {
        if(Request.Form["ExpertButton"]== "search")// this is by button!!!
        {
             some code.....

        }

        Response.Write("----");
         if(Request.Form["txtJavascriptMode"] == "true")
         {
            var id=Request.Form["expertID"];
            var deleteQuery="DELETE FROM InvestmanExperts WHERE ExpertID=@0";
            db.Execute(deleteQuery,id);
         }
    }
    db.Close();
}

There's something strange when I include this line:

Response.Write("----"+Request.Form["txtJavascriptMode"]);

Prior to:

if(Request.Form["txtJavascriptMode"] == "true");

The website's indentation appears off, yet the delete user function works correctly, why?

Thank you...

Answer №1

It seems that hidden fields are functioning correctly. To ensure proper functionality, consider including the ID deleteExpert in your form.

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

Using jQuery to handle events across multiple elements

Could I achieve something similar to this? I currently have several variables assigned to DOM elements. Rather than querying the DOM again to set event handlers, I would like to utilize the variables I already have. var a = $("#foo"); var b = $("#bar"); ...

Determine the vertical dimension of a child division once it has been integrated into an HTML document

My goal is to create a website with multiple pages without having to recreate the toolbar for each page. To achieve this, I have created a separate HTML file and CSS file specifically for the toolbar. On each page, I simply import the toolbar using the fo ...

Tips for Choosing the Right Objects in Vue.js

I have the following code that combines all objects in a person and stores them in an array called Cash:[] this.cash = person.userinvoice.concat(person.usercashfloat) Inside person.usercashfloat, there is an element called validate which sometimes equals ...

Transforming a canvas into a div element

Hey there, I'm looking to swap out one canvas for another but I'm not sure how it will look on the browser. Any help would be greatly appreciated. <div id="juego"> <canvas width="203" height="256" id="1" class="bloque"></canvas& ...

What is the process for issuing https requests with SuperAgent?

In my React Native Android project, I am utilizing SuperAgent, which works similarly to Node.js. My goal is to make an API call using the https protocol. However, when I simply use the following code: Req = SuperAgent .get(‘https://url...') ...

What steps can I take to ensure that my logos remain visible even when I close the menu and resize the window?

On my website, I have a menu of logos that are clickable. These logos always display except on smaller screens, where they need to be toggled to show using a hamburger menu. The menu toggles fine when it is on a smaller screen, but there is an issue when y ...

Error message stating that there is no property 'collection' in Firestore when using Firebase v9 modular syntax in Firebase Firestore

Working on a React application that makes use of Firebase Firestore for handling database operations, I recently upgraded to Firebase version 9 and adopted the modular syntax for importing Firebase services. Nevertheless, when attempting to utilize the co ...

Tips for testing views in ember.js using unit tests

We are currently delving into the world of Ember.js. Our development process is completely test-driven, and we aim to apply the same methodology to Ember.js. Having prior experience in test-driven development with Backbone.js apps using Jasmine or Mocha/Ch ...

Determine if an HTML element contains a specific class using JavaScript

Is there a simple method to determine if an HTML element possesses a particular class? For instance: var item = document.getElementById('something'); if (item.classList.contains('car')) Remember, an element can have more than one clas ...

IsContainer and IsModel properties in Dragular are not functioning properly with the accept or canBeAccepted methods

Scenario 1 : Let's consider using two containers, named A (Drag Source) and B (Drop Source). Code snippet : dragularService(containerLeft, { containersModel: [DragularconTainer], copy: true, canBeAccepted: function(el, source) { ...

Struggling with Vue's Router Transition fade in/out effect not functioning as expected?

Question: I've implemented Vue's Router and it switches between components without any issues. However, I added a <transition name="fade" mode="out=in"> around it but the fade effect is not working as expected. Desired ...

What methods can be used to validate an undefined value?

exploding right now if (myObject.myKey.myThing){ } undefined myThing cannot be read What approach can be taken to determine if myThing is defined before entering the if block? ...

I'm having trouble with my Laravel edit page not functioning properly when using vue.js. Can anyone help me troubleshoot

Currently, I am developing a dashboard to display details. Users can click on the edit button to modify their information. However, when I try to edit by clicking the button, nothing happens. It seems like the editing feature is not functioning properly, a ...

How can we include identical item names within a single JavaScript object?

My attempt at achieving the desired result involves creating an object like this: var obj = {id: id, items: "asdf", items: "sdff", test: varTest}; However, I face a challenge where I need to dynamically add two elements with the same name 'items&apo ...

Is there a way to streamline this generator without using recursion?

I need to develop a unique value generator that produces values within a specified range. The criteria are: all generated values must be distinct the order of values remains consistent upon each run of the generator each value should be significantly diff ...

Is it possible to incorporate a combination of es5 and es2015 features in an AngularJS application?

In my workplace, we have a large AngularJS application written in ES5 that is scheduled for migration soon. Rather than jumping straight to a new JS framework like Angular 2+ or React, I am considering taking the first step by migrating the current app to ...

What is causing the TypeError in Discord.js when trying to read the 'voice' property? Any help troubleshooting this issue would be greatly appreciated

Hey everyone, I'm having an issue with my play.js file that I obtained from a Source Bin. If anyone could provide some assistance, it would be greatly appreciated. const ytdl = require("ytdl-core"); const ytSearch = require("yt-search"); //Global que ...

The resize function triggers twice as many events with each window resize

While working on my website, I encountered a navigation issue when resizing the browser from desktop to mobile size. Initially, the mobile menu worked on load, as did the desktop navigation. However, after running a script with $(window).on('resize&ap ...

Difficulty in adjusting the height of the popover menu that appears when using the Select Validator in Material UI

I am having trouble adjusting the height of a popover that emerges from a select validator form in Material UI. Despite attempting various methods, including adding the following CSS to the main class: '& .MuiPopover-paper': { height: &apos ...

Have the functionality of right clicking and selecting Paste work in the input field using style=text and a button

Here is the code I am using: <script type="text/javascript"> $(document).ready(function() { $('#submit').prop('disabled', true); $('#links').change(function() { $('#submit').prop('disabled ...