it says function undefined yet defined below body of program's content.
<button type="button" class="btn btn-primary" data-dismiss="modal" id="cmdbrancheditok" onclick="cmdbrancheditok_onclick()"> @*add*@ function cmdbranchadd_onclick() { alert('hi'); @*$('#branchedit').modal({ show: true, backdrop: false }); document.getelementbyid('branchedit-branchcode').value = ""; document.getelementbyid('branchedit-branch').value = ""; document.getelementbyid('branchedit-companyid').value = "";*@ }
at moment, main body of function has been commented out test if can connect function. when run , pressed, return javarscript runtime error stating function in button in undefined.
edit #1: sorry, copied wrong line of code xd forgive me
<button style="float:left" id="cmdaddbranch" type="submit" class="btn btn-default" onclick="cmdbranchadd_onclick()">add branch</button>
while i'm @ it, here loaded scripts - function supposed call modal should alert now. it's doesn't.
<script src="~/js/jquery.js"></script> <script src="~/lib/bootstrap/js/bootstrap.js"></script> <script src="~/wijmo/controls/wijmo.min.js" type="text/javascript"></script> <script src="~/wijmo/controls/wijmo.input.min.js"></script> <script src="~/wijmo/controls/wijmo.grid.min.js" type="text/javascript"> </script> <script src="~/wijmo/controls/wijmo.chart.min.js"></script> <script src='http://code.jquery.com/jquery-latest.min.js' type='text/javascript'></script> <link href="~/wijmo/styles/wijmo.min.css" rel="stylesheet" />
edit #2: here's entire code block see if has problems. @{ viewbag.title = "branch"; }
<!-- script linkings --> <script src='http://code.jquery.com/jquery-latest.min.js' type='text/javascript'></script> <script src="~/lib/bootstrap/js/bootstrap.js"></script> <script src="~/wijmo/controls/wijmo.min.js" type="text/javascript"></script> <script src="~/wijmo/controls/wijmo.input.min.js"></script> <script src="~/wijmo/controls/wijmo.grid.min.js" type="text/javascript"></script> <script src="~/wijmo/controls/wijmo.chart.min.js"></script> <link href="~/wijmo/styles/wijmo.min.css" rel="stylesheet" /> @*<link href="/css/bootstrap.min.css" rel="stylesheet" /> --- s.o.b make things white. big "no, no" *@ @*list*@ <div id="divevents"> <div class="container"> <div class="row"> <div class="col-lg-11"> <br /><br /><br /> <h2 style="margin-bottom:5px; margin-top:5px;">branches</h2> <button style="float:left" id="cmdaddbranch" type="submit" class="btn btn-default" onclick="cmdbranchadd_onclick()">add branch</button> </div> </div> <br /> <div class="row"> <div class="col-lg-12"> <div id="branchgrid" class="grid"></div> </div> </div> <br /> <div class="row"> <div class="btn-group col-md-7" id="naviagtionpageevent"> <button type="button" class="btn btn-default" id="btnmovetofirstpageevent"> <span class="glyphicon glyphicon-fast-backward"></span> </button> <button type="button" class="btn btn-default" id="btnmovetopreviouspageevent"> <span class="glyphicon glyphicon-step-backward"></span> </button> <button type="button" class="btn btn-default" disabled style="width:100px" id="btncurrentpageevent"></button> <button type="button" class="btn btn-default" id="btnmovetonextpageevent"> <span class="glyphicon glyphicon-step-forward"></span> </button> <button type="button" class="btn btn-default" id="btnmovetolastpageevent"> <span class="glyphicon glyphicon-fast-forward"></span> </button> </div> </div> </div> </div> @*edit detail*@ <div class="modal fade" id="branchedit"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true"> × </button> <h4 class="modal-title">branch edit</h4> </div> <div class="modal-body"> <dl class="dl-horizontal"> <dt>branch code</dt> <dd> <input class="form-control" id="branchedit-branchcode" type="text" /> </dd> <dt>branch</dt> <dd> <input class="form-control" id="branchedit-branch" type="text" /> </dd> <dt>company id</dt> <dd> <input class="form-control" id="branchedit-companyid" type="text" /> </dd> </dl> </div> <div class="modal-footer"> <button type="button" class="btn btn-primary" data-dismiss="modal" id="cmdbrancheditok" onclick="cmdbrancheditok_onclick()"> ok </button> <button type="button" class="btn btn-danger" data-dismiss="modal" id="cmdbrancheditcancel"> cancel </button> </div> </div> </div> </div> @*loading*@ <div class="modal fade" id="loading" tabindex="-1" role="dialog" aria-labelledby="loading..." aria-hidden="true"> <div class="modal-dialog" style="width: 220px;"> <div class="modal-content"> <div class="modal-header"> <h4 class="modal-title">loading...</h4> </div> <div class="modal-body"> <img src="/img/progress_bar.gif" /> </div> </div> </div> </div> @*module*@ <script type="text/javascript"> var branches; var branchgrid; var btnfirstpageevent; var btnpreviouspageevent; var btnnextpageevent; var btnlastpageevent; var btncurrentpageevent; @*edit*@ function cmdbranchedit_onclick() { branches.edititem(branches.currentitem); $('#branchedit').modal({ show: true, backdrop: false }); var branch = branches.currentedititem; document.getelementbyid('branchedit-branchcode').value = branch.branchcode ? branch.branchcode : ''; document.getelementbyid('branchedit-branch').value = branch.branch ? branch.branch : ''; document.getelementbyid('branchedit-companyid').value = branch.companyid ? branch.companyid : ''; } @*add*@ $(document).ready(function(){ function cmdbranchadd_onclick() { alert('hi'); @*$('#branchedit').modal({ show: true, backdrop: false }); document.getelementbyid('branchedit-branchcode').value = ""; document.getelementbyid('branchedit-branch').value = ""; document.getelementbyid('branchedit-companyid').value = "";*@ } } @*delete*@ function cmdbranchdelete_onclick() { branches.edititem(branches.currentitem); var id = branches.currentedititem.id; var branchdescription = branches.currentedititem.branch; if (confirm("delete " + branchdescription + "?") == true) { $.ajax({ type: "delete", url: "/api/deleteevent/" + id, contenttype: "application/json; charset=utf-8", datatype: "json", statuscode: { 200: function () { window.location.reload(); }, 404: function () { alert("not found"); }, 400: function () { alert("bad request"); } } }); } } @*save edit*@ function cmdbrancheditok_onclick() { if (confirm("save event?") == true) { var branch = new object(); branch.branchcode = document.getelementbyid('branchedit-branchcode').value; branch.branch = document.getelementbyid('branchedit-branch').value; branch.companyid = document.getelementbyid('branchedit-companyid').value; var data = json.stringify(event); // add new if (branch.id == 0) { $.ajax({ type: "post", url: "/api/addevent", contenttype: "application/json; charset=utf-8", datatype: "json", data: data, success: function (id) { if (id > 0) { window.location.reload(); } else { alert("not added"); } } }); // edit } else { $.ajax({ type: "put", url: "/api/updateevent/" + branch.id, contenttype: "application/json; charset=utf-8", datatype: "json", data: data, statuscode: { 200: function () { window.location.reload(); }, 404: function () { alert("not found"); }, 400: function () { alert("bad request"); } } }); } } } @*list functions*@ function getbranches() { var branches = new wijmo.collections.observablearray(); $('#loading').modal('show'); $.ajax({ url: '/api/event', cache: false, type: 'get', contenttype: 'application/json; charset=utf-8', data: {}, success: function (results) { $('#loading').modal('hide'); if (results.length > 0) { (i = 0; < results.length; i++) { branches.push({ editid: "<button class='btn btn-primary btn-xs' data-toggle='modal' id='cmdbranchevent' onclick='cmdbranchedit_onclick()'>edit</button>", deleteid: "<button class='btn btn-danger btn-xs' data-toggle='modal' id='cmdbranchevent' onclick='cmdbranchdelete_onclick()'>delete</button>", id: results[i]["id"], branchcode: results[i]["branchcode"], branchdescription: results[i]["branch"], companyid: results[i]["companyid"], }); } } else { alert("no data."); } } }).fail( function (xhr, textstatus, err) { alert(err); } ); return branches; } @*delete*@ function deletebranch(id) { $.ajax({ type: "delete", url: "/api/deleteevent/" + id, contenttype: "application/json; charset=utf-8", datatype: "json", data: { id: branchid }, success: function (response) { alert("branch deleted."); window.location.reload(); }, failure: function (response) { alert("error - " + response.d); }, error: function (e) { } }); window.location.reload(); } function updatenavigatebuttonsevent() { if (branches.pagesize <= 0) { document.getelementbyid('naviagtionpageevent').style.display = 'none'; return; } document.getelementbyid('naviagtionpageevent').style.display = 'block'; if (branches.pageindex === 0) { btnfirstpageevent.setattribute('disabled', 'disabled'); btnpreviouspageevent.setattribute('disabled', 'disabled'); btnnextpageevent.removeattribute('disabled'); btnlastpageevent.removeattribute('disabled'); } else if (branches.pageindex === (branches.pagecount - 1)) { btnfirstpageevent.removeattribute('disabled'); btnpreviouspageevent.removeattribute('disabled'); btnlastpageevent.setattribute('disabled', 'disabled'); btnnextpageevent.setattribute('disabled', 'disabled'); } else { btnfirstpageevent.removeattribute('disabled'); btnpreviouspageevent.removeattribute('disabled'); btnnextpageevent.removeattribute('disabled'); btnlastpageevent.removeattribute('disabled'); } btncurrentpageevent.innerhtml = (branches.pageindex + 1) + ' / ' + branches.pagecount; } $(document).ready(function () { btnfirstpageevent = document.getelementbyid('btnmovetofirstpageevent'); btnpreviouspageevent = document.getelementbyid('btnmovetopreviouspageevent'); btnnextpageevent = document.getelementbyid('btnmovetonextpageevent'); btnlastpageevent = document.getelementbyid('btnmovetolastpageevent'); btncurrentpageevent = document.getelementbyid('btncurrentpageevent'); branches = new wijmo.collections.collectionview(getbranches()); branchgrid = new wijmo.grid.flexgrid('#branchgrid'); branchgrid.initialize({ columns: [ { "header": "edit", "binding": "editid", "width": 60, "allowsorting": false, "iscontenthtml": true }, { "header": "delete", "binding": "deleteid", "width": 60, "allowsorting": false, "iscontenthtml": true }, { "header": "branch code", "binding": "branchcode", "allowsorting": false, "width": "4*" }, { "header": "company id", "binding": "companyid", "allowsorting": false, "width": 80 }, { "header": "branch", "binding": "branchdescription", "allowsorting": false, "width": "4*" }, ], autogeneratecolumns: false, itemssource: brances, isreadonly: true, selectionmode: wijmo.grid.selectionmode.row }); branchgrid.trackchanges = true; branches.pagesize = 15; }); updatenavigatebuttonsevent(); // page button events btnfirstpageevent.addeventlistener('click', function () { branches.movetofirstpage(); updatenavigatebuttonsevent(); }); btnpreviouspageevent.addeventlistener('click', function () { branches.movetopreviouspage(); updatenavigatebuttonsevent(); }); btnnextpageevent.addeventlistener('click', function () { branches.movetonextpage(); updatenavigatebuttonsevent(); }); btnlastpageevent.addeventlistener('click', function () { branches.movetolastpage(); updatenavigatebuttonsevent(); }); }); </script>
tried rao's suggestion - still nothing :( starting pain in ass..)
you have code method called
cmdbranchadd_onclick
but element references function called
cmdbranchedit_onclick