简体   繁体   中英

Passing variable to form action javascript and HTML

I have a form to update an entity called Equipment. This form must pass in the action the route '/' serial number of the equipment.

How can i pass the serial number of this entity?

This form is in a modal. See below:

<form
 name="editEquipmentForm"
 id="editEquipmentForm"
 class="form-horizontal"
 method="POST"
 action="/equipments/SERIALNUMBER"  <-- I need pass the serial here
>

I get the variable in another file called request.ejs. This file is included by the index.ejs, that has the modal.

Here's how i get the serialnumber:

function getEquipmentData(serialNumber) {
var serialNumber = serialNumber;
setEditInputs();
document.getElementById("serialnumber2").value = serialNumber;

$.ajax({
  url: "equipments/" + serialNumber,
  type: "get",
  success: function(response) {
    document.getElementById("sha1Curve2").value = response[0].sha1Curve;
    document.getElementById("equipmentName2").value =
      response[0].equipmentName;
    document.getElementById("position2").value = response[0].position;
    document.getElementById("idealRangeMin2").value =
      response[0].idealRangeMin;
    document.getElementById("idealRangeMax2").value =
      response[0].idealRangeMax;
  },
  error: function(xhr) {
    console.log(xhr);
  }
});}

This function is called when i open the modal.

Thanks for any tips.

Try this:

document.forms.editEquipmentForm.action = '/equipments/' + serialNumber;

Or this:

var form = document.getElementById('editEquipmentForm');
form.action = '/equipments/' + serialNumber;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM