Retrieve the Form by ID: Use document.getElementById(formId)

Explanation:

  1. Retrieve the Form by ID: Use document.getElementById(formId) to select the specific form.
  2. Query Hidden Input: Use form.querySelector('input[name="UserId"]') to find the hidden field within that form.
  3. Get the Value: Access the value of the hidden field using hiddenInput.value.
  4. Dynamic Form IDs: Pass the form ID to the getUserId function dynamically (e.g., form1, form2).
function getUserId(formId) {
    // Get the form element by ID
    var form = document.getElementById(formId);
    
    // Find the hidden input with name="UserId" inside the form
    var hiddenInput = form.querySelector('input[name="UserId"]');
    
    // Get the value of the hidden input
    if (hiddenInput) {
        var userId = hiddenInput.value;
        console.log("UserId:", userId);
        // Do something with the UserId
        alert("UserId: " + userId);
    } else {
        console.error("No hidden input with name='UserId' found in form with ID:", formId);
    }
}

 

Up Next
    Ebook Download
    View all
    css
    Read by 0 people
    Download Now!
    Learn
    View all
    GE HealthCare will never ask for payment to process documents, refer you to a third party to process