Invoking a function means calling another one simultaneously

There are two buttons in my code:

The button on the right triggers a function called update():

 <script>
 function update(buttonid){
   document.getElementById(buttonid).disabled = true;

   event.stopPropagation();

   var textboxid = buttonid.slice(0, -2);
   var id= textboxid.substr(0, textboxid.indexOf('_'));
   var columnid= textboxid.substr(textboxid.indexOf('_')+1, textboxid.length);
   var value=document.getElementById(textboxid).value;

   var str=textboxid+"_"+value;


   if (window.XMLHttpRequest) {
     // code for IE7+, Firefox, Chrome, Opera, Safari
     xmlhttp = new XMLHttpRequest();
   } else {
     // code for IE6, IE5
     xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
   }

   xmlhttp.open("GET","ListaRyF/Update?q="+str,true);
   xmlhttp.send();
 }
 </script>

The button on the left calls an empty function named 'row_update()'.

The issue here is that when I click the left button, it also activates the function of the right button.

The HTML code for the buttons is as follows:

Left Button:

<button class="btn btn-default" id="row_1" onclick="row_update('1_9');">
<i class="fa fa-save fa-fw button-row"></i>
</button>

Right Button:

<button class="btn btn-default" id="1_2_b" onclick="update('1_2_b');">
<i class="fa fa-save fa-fw"></i>
</button>

Can anyone help me with resolving this issue?

Thank you!

Answer №1

you need to prevent event bubbling from occurring

give this a shot:

left-button:

<button class="btn btn-default" id="row_1" onclick="row_update(event,'1_9');">
<i class="fa fa-save fa-fw button-row"></i>
</button>

right-button:

<button class="btn btn-default" id="1_2_b" onclick="update(event,'1_2_b');">
<i class="fa fa-save fa-fw"></i>
</button>


 <script>
 function update(event,buttonid){
   document.getElementById(buttonid).disabled = true;

   event.stopPropagation();

   var textboxid = buttonid.slice(0, -2);
   var id= textboxid.substr(0, textboxid.indexOf('_'));
   var columnid= textboxid.substr(textboxid.indexOf('_')+1, textboxid.length);
   var value=document.getElementById(textboxid).value;

   var str=textboxid+"_"+value;

   if (window.XMLHttpRequest) {
     // code for IE7+, Firefox, Chrome, Opera, Safari
     xmlhttp = new XMLHttpRequest();
   } else {
     // code for IE6, IE5
     xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
   }

   xmlhttp.open("GET","ListaRyF/Update?q="+str,true);
   xmlhttp.send();

   return false;
 }


function row_update(event,buttonid)
{
 event.stopPropagation();
  /* your codes goes here */

return false;
}
 </script>

from now on, they will function independently without interference. Ensure you include the event parameter in your actions

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

Is it acceptable that req.body is void of content? Should we reconsider this approach?

As a beginner in express, I am working on incorporating a basic login feature into my project. However, I am facing some confusion when it comes to passing data around. There are a few aspects that are perplexing me. I currently store the input value i ...

The error message "gulp error - _.flattenDeep is not a function when using gulp.watch" is indicating

Whenever I run a watch task, why am I encountering the TypeError: _.flattenDeep is not a function error? Below is the content of my gulpfile.js : var gulp = require('gulp'); var sass = require('gulp-sass'); var sourcemaps = require(&a ...

Optimizing Bootstrap popover responsiveness for elements with excessive length to ensure a smooth display experience

I am currently working on creating a popover that remains in position when hovered over, specifically for elements that are too large to fit on the screen. However, I am facing some issues with my current implementation: <template> <div class ...

find all the possible combinations of elements from multiple arrays

I have a set of N arrays that contain objects with the same keys. arr[ {values:val1,names:someName},   {values:val2,names:otherName}, ] arr2[   {values:valx,names:someNamex}, {values:valy,names:otherNamey}, ] My goal is to combine all possible c ...

Accessing multi-dimensional array properties in PHP with JavaScript integration

In my PHP code, I have an array structured like this: <?php $data = array(); $data[0] = array('year' => 2001, 'month' => array( 'January' => array('val1' => 1000, 'v ...

The issue persists with json_encode as it fails to display the desired JSON output

<?php include("db_connection.php"); if(isset($_POST['id']) && isset($_POST['id']) != "") { // retrieve User ID $user_id = $_POST['id']; // Retrieve User Details from database $query = "SELECT * FROM prod ...

Adjust the hue as you scroll

I've been searching for a solution to this issue, but I haven't been able to make it work. My goal is to have the page header change from a transparent background to a red background as the user starts scrolling down the page. $(window).on("s ...

Using Angular routing without relying on a web server to load templates

Can templates be loaded in Angular without a web server? I came across an example here: https://groups.google.com/forum/#!topic/angular/LXzaAWqWEus but it seems to only print the template paths instead of their content. Is there a functioning example of t ...

Learn how to utilize Selenium Web Driver with Java to interact with waypoints located within a map canvas on an HTML5 webpage

Struggling with Selenium Web Driver (Java) - How to interact with waypoints on an HTML5 canvas map? I am currently trying to implement drag and drop functionality on a canvas map within an HTML5 page, but I'm facing some challenges. https://i.sstati ...

Balanced Height Panels - Utilizing Flexbox and flex-wrap: wrap

i'm having trouble with a layout design, specifically with getting the columns to be equal height, especially when the text wraps around. Can anyone provide some guidance? https://i.stack.imgur.com/bbDKj.png Within my HTML template, there are multipl ...

Alert-Enabled Random Number Generation Tool

I'm struggling to create a program that randomly generates a number between 1 and 20. If the number is less than 10, it should display "fail," and if it's greater than 10, it should display "success." I can't seem to figure out where I went ...

Having trouble with changing the state within an AngularJS (Ionic Framework) controller?

My goal is to switch views within the Search controller after receiving search results from the server through $http. However, my current approach doesn't seem to be working as intended. I also need to pass the response to the new view for displaying ...

Arranging divs with CSS positioning

I struggle with positioning divs, especially in this particular situation. I am attempting to position boxes in the following layout: _ ___ _ |_|| ||_| _ | | |_||___| Is there a way to avoid manually defining pixel positions for each box and ins ...

Dynamic count down using JavaScript or jQuery

I am looking for a way to create a countdown timer that I can adjust the time interval for in my database. Basically, I have a timestamp in my database table that might change, and I want to check it every 30 seconds and update my countdown accordingly. H ...

Issues with jQuery focus function in Internet Explorer 11

Is there a way to set the focus on an anchor tag using the URL? Anchor Tag: <a id='714895'>&nbsp;</a> URL: jQuery Code: try { if(document.URL.indexOf("?ShowAllComments=True#") >= 0){ var elementClicked = "#" +location.hre ...

jquery slider for inputting phone number on a mobile device

I am currently working on enhancing the user interface by implementing a feature where users can select a mobile number using a slider. The idea is that the user will choose a digit between 0 and 9 using the slider, then confirm their selection by pressing ...

I am experiencing an issue where Discord.js is unable to assign a role to a new member upon joining my server

I'm trying to set up my bot to automatically assign a specific role to new members when they join the server. However, I keep encountering a strange error that I can't seem to figure out. Here is the code snippet in question: const { GuildMember ...

What is the best way to reposition the origin of the canvas to the center?

As a beginner in html and JavaScript, I am currently working on a program that involves points and lines in a coordinate system. However, the canvas for html5 has its origin at the upper corner, and I need to create a coordinate system with the origin at ...

Picture fails to load on Ionic app on the device

Currently, I am utilizing Ionic 3 for my project. The location of the images file is \src\assets\img. This pertains to a basic page implementation. export class BasicPage { items = []; constructor(public nav: NavController ,private adm ...

The rotation function of the div element is malfunctioning

Exploring CSS has led me to a peculiar issue where transform:rotate is not functioning as expected. Here is an instance of the animation not triggering: jsFiddle CSS .close { width:100px; height:100px; background:#00f; ...