Gautam Puhan

Gautam Puhan

  • NA
  • 43
  • 1.5k

Mvc and Jquery Selectors

May 24 2018 4:10 AM
i am new in MVC n jQuery..
 
The Error is that jquery selector can't read the textbox values  ie Eid,Ename..not defined..
 
</div>
<button id="create-user">Create new user</button>
<input type="button" id="btnSave" value="Save" />
<div id="dialog-form" title="Create new user" style="display:none">
<p class="validateTips">All form fields are required.</p>
<form>
<fieldset>
<label for="id">Emp id</label>
<input type="text" id="txtId" />
<label for="name">Name</label>
<input type="text" name="name" id="name" value="Enter your Name" class="text ui-widget-content ui-corner-all">
<label for="email">Email</label>
<input type="text" name="email" id="email" value="[email protected]" class="text ui-widget-content ui-corner-all">
<label for="password">Password</label>
<input type="password" name="password" id="password" value="xxxxxxx" class="text ui-widget-content ui-corner-all">
<label for="salary">Salary</label>
<input type="number" name="salary" id="salary" value="0" class="text ui-widget-content ui-corner-all">
<label for="deptname">Dept Name</label>
<input type="text" name="deptname" id="deptname" value="Enter Dept Name" class="text ui-widget-content ui-corner-all">
<label for="Job">Job</label>
<input type="text" name="job" id="job" value="Enter job" />
<label for="status">Status</label>
<input type="checkbox" id="cbChecked" name="status" class="text ui-widget-content ui-corner-all" />
<!-- Allow form submission with keyboard without duplicating the dialog button -->
<input type="submit" tabindex="-1" style="position:absolute; top:-1000px">
</fieldset>
</form>
</div>
</body>
<script type="text/javascript">
$("#btnSave").on('click',function (e) {
var arr = new Array();
$("#dialog-form").find(":input").each(function () {
arr.push({
Eid: $(this).find("#txtId").val(),
Ename: $(this).find("#name").html(),
Email: $(this).find("#email").html(),
Password: $(this).find("#password").html(),
ESal: $(this).find("#salary").html(),
DeptName: $(this).find("#deptname").html(),
EJob: $(this).find("#job").html(),
Status: $(this).find("#cbChecked").html()
})
})
$.ajax({
type: 'POST',
url: '/Emp/Create',
data:JSON.stringify(arr),
dataType:"json",
contentType: 'application/json; charset=utf-8',
success: function (data) {
alert("success");
},
error:function(d){
alert("Failed");
}
})
})
</script>

Answers (1)