0

My code is

<div class="flex-shrink-1 " id="request_btn<?= $contact['id'] ?>">
  <button data-request-to="<?= $contact['id'] ?>" data-request-from="<?= $_SESSION['id'] ?>" class="btn btn-sm btn-primary send_request" >Send Request
  </button>
</div>
<div class="flex-shrink-1 " id="del_request<?= $contact['id'] ?>">
  <button data-request-to="<?= $contact['id'] ?>" data-request-from="<?= $_SESSION['id'] ?>" class="btn btn-sm btn-danger del_request"  style="display:none;">Reject Request
  </button>
</div>

I want to use in JavaScript

document.getElementById("del_request[int_values]").setAttribute('style','display:none');

document.getElementById("del_request[int_values]").removeAttribute('style'); 

and

document.getElementById("send_request[int_values]").setAttribute('style','display:none');

document.getElementById("send_request[int_values]").removeAttribute('style'); 

I hope you will understand, How can I add send_request[int_values] in javascript

  • what have you done so far? and this is not related to PHP after all – hassan Oct 13 '21 at 07:54
  • Welcome to Stack Overflow! Visit the [help], take the [tour] to see what and [ask]. If you get stuck, post a [mcve] of your attempt, noting input and expected output using the [`[<>]`](https://meta.stackoverflow.com/questions/358992/ive-been-told-to-create-a-runnable-example-with-stack-snippets-how-do-i-do) snippet editor. Please do not post PHP but instead post rendered HTML – mplungjan Oct 13 '21 at 07:56
  • 1
    If the Html in that first block is what is actually seen in the browser, it will most likely be in error. The value of the `id` property must adhere to certain rules. See https://stackoverflow.com/a/31773673/936293. Even if your values are valid, they will be treated as static strings literally. – Old Geezer Oct 13 '21 at 08:11
  • If the Html in that first block is what is seen in your backend server, then you need to indicate what technology or scripting engine you are using. – Old Geezer Oct 13 '21 at 08:13

1 Answers1

0

you can do something like

var a = [int_values] // for multiple values, can be taken as input of a function

var elementId = "send_request" + a ;

document.getElementById(elementId)