when pass data from table html to bootstrap model it not passed so what is issue i don't know
i need to pass server ip and location and printer name and id to bootstrap model
it display perfect on table html but it not passed to bootstrap model
so what is issue and how to solve it please
TypeScript
Printer Name
Location Name
@*
Server IP
*@
Company: @TempData["Company"]
Branch: @TempData["Branch"]
Env: @TempData["Environment"]
*@
Close
Save changes
@if (ViewData["SearchResults"] != null)
{
ID
BranchType
UserPC
PrinterName
ArabicConfig
Status
Location Name
>Action
@foreach (DataRow row in table.Rows)
{
>@row["AutoID"]
@row["BranchType"]
@row["UserPC"]
@row["PrinterName"]
@row["ArabicConfig"]
@row["Status"]
@row["DisplayName"]
Edit
}
}
else
{
@Model.errormsg
}
@section scripts {
$(document).ready(function(){
$('#editshiftlabel').click(function () {
console.log("success edit")
var id = $(this).data('ShiftId');
console.log(id);
var serverIP = $(this).data('serverip');
var printername = $(this).data('printername');
var location = $(this).data('Location');
$('#edit-id').val(id);
$('#edit-ip').val(serverIP);
$('#edit-printername').val(printername);
$('#edit-Location').val(location);
$('#editshelflabelModal').modal('show');
});
Deepak RawatRank #646 · 3.7K reputationPosted Jun 23, 2023, 3:46 AM EDT
The issue seems to be with the data attribute names in the HTML markup. When retrieving the data using jQuery, you should use the correct attribute names that you have defined.
In your HTML, you have used the data attributes
data-id,data.Location,data.printername, anddata.serveripto store the corresponding values. However, in your JavaScript code, you are attempting to retrieve the data using different attribute names (ShiftId,serverip,printername, andLocation).To fix the issue, update your JavaScript code to use the correct attribute names when retrieving the data. Here's the corrected code:
$(document).ready(function () { $('#editshiftlabel').click(function () { console.log("success edit"); var id = $(this).data('id'); console.log(id); var serverIP = $(this).data('serverip'); var printername = $(this).data('printername'); var location = $(this).data('location'); $('#edit-id').val(id); $('#edit-ip').val(serverIP); $('#edit-printername').val(printername); $('#edit-Location').val(location); $('#editshelflabelModal').modal('show'); }); });be sure to use lowercase attribute names (
data-id,data-location,data-printername, anddata-serverip) when retrieving the data using thedatamethod in jQuery.With these changes, the data should be passed correctly from the table HTML to the Bootstrap modal.
Amit MohantyRank #112 · 20K reputationPosted Jun 22, 2023, 9:36 AM EDT
The id attribute should be unique within the HTML document. In your code, you have multiple buttons with the id attribute of "editshiftlabel". May be this is the issue. To fix this issue, you can use a class instead of an id for your buttons. Replace the id attribute with class attribute in the button tag, like this:
Now, update your JavaScript code to select the button using the class selector (.editshiftlabel) instead of the id selector (#editshiftlabel):
$(document).ready(function(){ $('.editshiftlabel').click(function () { console.log("success edit"); var id = $(this).data('id'); console.log(id); var serverIP = $(this).data('serverip'); var printername = $(this).data('printername'); var location = $(this).data('location'); $('#edit-id').val(id); $('#edit-ip').val(serverIP); $('#edit-printername').val(printername); $('#edit-Location').val(location); $('#editshelflabelModal').modal('show'); }); });ahmed salahRank #2,240 · 628 reputationPosted Jun 22, 2023, 11:05 AM EDT
I do as above and isue still not solved
i give button class and issue not solved
can you please help me
Amit MohantyRank #112 · 20K reputationPosted Jun 23, 2023, 3:36 AM EDT
Try this once:
$(document).ready(function() { $(document).on('click', '.editshiftlabel', function() { console.log("success edit"); var id = $(this).data('id'); console.log(id); var serverIP = $(this).data('serverip'); var printername = $(this).data('printername'); var location = $(this).data('location'); $('#edit-id').val(id); $('#edit-ip').val(serverIP); $('#edit-printername').val(printername); $('#edit-Location').val(location); $('#editshelflabelModal').modal('show'); }); });