I'm trying to get the selected value from menu into country variable, but I keep getting error: No parameterless constructor defined.
UpdateClient function gets invoke by clicking on the button Save.
I'm using parent() and find() functions to get that control, but I guess I'm using them on the wrong way.
This is my script:
function UpdateClient() {
var ar = $(this).parent().parent().parent().find('.clientIdValue').val();
var name = $(this).parent().parent().parent().find($('input[name=cname]')).val();
var address = $(this).parent().parent().parent().find($('input[name=caddress]')).val();
var zip = $(this).parent().parent().parent().find($('input[name=czip]')).val();
var city = $(this).parent().parent().parent().find($('input[name=ccity]')).val();
var country = $(this).parent().parent().parent().find($('select[name=ccountries] option:selected').text());
$.ajax({
type: "POST",
url: 'clients.aspx/UpdateClient',
data: JSON.stringify({ "ID": ar, "ClientName": name, "Address": address, "ZipCode": zip, "city": city, "Country": country}),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccessUpdate,
error: OnErrorUpdate,
});
function OnSuccessUpdate(data) {
window.location.reload();
}
function OnErrorUpdate(result) {
console.log(result);
}
}
And this is my HTML on aspx page:
<asp:Repeater ID="clientRepeat" runat="server">
<ItemTemplate>
<div class="item">
<div class="heading">
<span>
<asp:Label runat="server" ID="TeamMemberName" Text='<%#Eval("ClientName")%>'></asp:Label></span>
<i>+</i>
</div>
<div class="details">
<input type="hidden" name="clientID" class="clientIdValue" value="<%#Eval("ClientID")%>" />
<ul class="form">
<li>
<label>Client name:</label>
<input type="text" class="in-text" name="cname" value="<%#Eval("ClientName") %>" />
</li>
<li>
<label>Zip/Postal code:</label>
<input type="text" class="in-text" name="czip" value="<%#Eval("ZipCode") %>" />
</li>
</ul>
<ul class="form">
<li>
<label>Address:</label>
<input type="text" class="in-text" name="caddress" value="<%#Eval("Address") %>" />
</li>
<li>
<label>Country:</label>
<select name="ccountries">
<option value="AF">Afghanistan</option>
<option value="AX">Aland Islands</option>
<option value="AL">Albania</option>
<option value="DZ">Algeria</option>
<option value="AS">American Samoa</option>
<option value="AD">Andorra</option>
<option value="AO">Angola</option>
<option value="AI">Anguilla</option>
<option value="AQ">Antarctica</option>
<option value="AG">Antigua and Barbuda</option>
<--...And all the others...-->
</select>
</li>
</ul>
<ul class="form last">
<li>
<label>City:</label>
<input type="text" class="in-text" name="ccity" value="<%#Eval("City") %>" />
</li>
</ul>
<div class="buttons">
<div class="inner">
<button class="btn green" onclick="UpdateClient.call(this);">Save</button>
<button class="btn red" onclick="DeleteClient.call(this);">Delete</button>
</div>
</div>
</div>
</div>
</ItemTemplate>
</asp:Repeater>
What I'm doing wrong with selecting selected option? Is that even right way to do it? All other variables get right values from textboxes.
.closest().