I have a table set up to display information from a model. Each row has an edit and delete button. The delete button works fine as it passes the models id (area.areaID) to a a javascript function and it works fine. The edit button however is passes all variables of the model to a javascript function but the strings are not passing correctly and only the int variable "area.zone" is being passed correctly. The javascript function is suppose to change the placeholders of some inputs in a popup.
The table
@foreach (var area in Model)
{
<tr>
<td>
@Html.DisplayFor(ModelItem => area.areaName)
</td>
<td>
@Html.DisplayFor(ModelItem => area.zone)
</td>
<td>
@Html.DisplayFor(ModelItem => area.areaCommunity)
</td>
<td>
@Html.DisplayFor(ModelItem => area.city)
</td>
<td>
@Html.DisplayFor(ModelItem => area.region)
</td>
<td>
<input class="btn btn-primary button button4" type="button" value="Edit" onclick="editRecord(@area.areaName, @area.zone, @area.areaCommunity, @area.city, @area.region)"/>
<input class="btn btn-danger button button4" type="button" value="Delete" onclick="deleteRecord(@area.areaID)"/>
</td>
</tr>
}
The script function
function editRecord(editName, editZone, editAC, editCity, editRegion) {
$('#editModal').modal('show');
$('#editAreaName').attr("placeholder", editName);
$('#editZone').attr("placeholder", editZone);
$('#editAreaCommunity').attr("placeholder", editAC);
$('#editCity').attr("placeholder", editCity);
$('#editRegion').attr("placeholder", editRegion);
}
The form in the popup with the inputs. The zone place holder is being changed if ONLY the zone parameter is passed.
<form>
<div class="form-group">
Area<input class="form-control" type="text"
placeholder="" id="editAreaName" />
</div>
<div class="form-group">
Zone<input class="form-control" type="text"
placeholder="" id="editZone" />
</div>
<div class="form-group">
Area Community<input class="form-control" type="text"
placeholder="" id="editAreaCommunity" />
</div>
<div class="form-group">
City<input class="form-control" type="text"
placeholder="" id="editCity" />
</div>
<div class="form-group">
Region<input class="form-control" type="text"
placeholder="" id="editRegion" />
</div>
<div class="form-group">
<input type="submit" , value="Update" class="btn btn-primary button button4" id="submitEdit" />
</div>
</form>
I am currently getting an error show in the visual studio debugger saying "ReferenceError: BATU is not defined at HTMLInputElement.onclick (https://localhost:44379/:187:166)" BATU being an area.areaName. Also if there is a hyphen in the name the value shown in the reference error is cut off before the hyphen