Click here to Skip to main content
15,672,471 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi! I built a button in run time and an onclick event in running when I press on the button I got an error Uncaught SyntaxError: Unexpected token } dont know why the code doesnt miss any "}"
the page:
(the button is caled "editButton2 "

@model ProjectUI.Models.UserViewModel
@using ProjectBL

@{
ViewBag.Title = "RegistrationSystem";
}
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}

<script src="~/jquery-1.10.2.js"></script>
<script>
$(function () {
$(document).submit(function (evt) {
evt.preventDefault();
});
})
</script>


<script>


$(document).ready(function(){

var counter2 = 0;



$("#btn_addNumber").click(function () {
if(counter2==0)
{
counter2 = $("#btn_addNumber").attr("name");
}
var newTextBox = $(document.createElement('input'))
.attr("id", counter2);
counter2++;

var editButton2 = $('<input/>').attr({ type: 'button', name: 'btn', value: 'Button', onclick: '(fn_changeNumber(' + counter2 + ')' })


newTextBox.appendTo("#PhoneNumbers");
editButton2.appendTo("#PhoneNumbers");
})
})

function fn_changeNumber(pnCode) {
var phoneNumberCode = pnCode;
var phoneNumber = $("#" + pnCode + "").val();

debugger;
var target = "/User/ChangePhoneNumber/?i=" + parseInt(phoneNumberCode) + "&number=" + parseInt(phoneNumber);
$.ajax({
url: target,
type: "POST",
async: true,
success: function (result) {
$("#ChangeResult").html(result);
},
})
}

</script>

RegistrationSystem


@using (Html.BeginForm())

{


RegistrationSystem



@Html.LabelFor(model => model.userName)


@Html.EditorFor(model => model.userName)
@Html.ValidationMessageFor(model => model.userName)


@Html.DropDownListFor(model => model.userStatusCode, Model.selectList, "---status---", new { id = "ddlArea" })



<label>phoneMumbers</label>



@if(Model.userPhoneNumbers!=null)
{
foreach (TblPhoneNumber item in Model.userPhoneNumbers)
{
<input type="text" id="@item.pnCode" value="@item.pnNumber"/>
<button value="change" onclick="fn_changeNumber(@item.pnCode)"></button>

}
}
@* <button id="btn_addNumber"value="add new phone number" onclick="fn_addNumber()"></button>*@


@*<button value="add new phone number" onclick="fn_addNumber(@Model.userPhoneNumbers.Count)"></button>*@
<button id="btn_addNumber"value="add new phone number" name="@Model.userPhoneNumbers.Count" ></button>


<label>Emails</label>






@Html.LabelFor(model => model.userUsePhone)


@Html.EditorFor(model => model.userUsePhone)
@Html.ValidationMessageFor(model => model.userUsePhone)



<input type="submit" value="Create" />



}


@Html.ActionLink("Back to List", "Index")
)
Posted
Comments
DamithSL 4-Nov-14 9:40am    
Improve question : format the code

1 solution

It is clear that you have one more } than { - probably the last one...
Try and format your code to some pretty look and you will see where the spare } is...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900