Good morning all,
I'm sure this is a gimme, but I have no idea where this issue is coming from.
I have the following lines in a view:
<fieldset>
<dl>
<dt>
<label for="FormTypes">Form Type:</label>
</dt>
<dd>
<% =Html.DropDownList("FormTypes", "All") %>
</dd>
</dl>
</fieldset>
<fieldset>
<dl>
<dt>
<label for="Parts">Form Part:</label>
</dt>
<dd>
<% =Html.DropDownList("Parts", "All") %>
</dd>
</dl>
</fieldset>
This causes no problems, but when adding the following script to the top of to update Parts based on the selection of form type (following the answer to this SO question http://stackoverflow.com/questions/1585642/bind-dropdownlists-with-jquery-in-asp-net)
<script type="text/javascript">
<!--
$('#FormTypes').change(function() {
var val = $(this).val();
$parts = $('#Parts');
$.ajax({
url: '<%= Url.Action('FormParts') %>',
dataType: 'json',
data: { ID: val },
success: function(parts) {
$.each(parts, function(i, part) {
$parts.append('option value="' + part.ID+ '">' + part.Code + '</option>');
});
},
error: function() {
alert('Failed to retrieve parts list.');
}
});
});
//-->
</script>
(where the FormParts action will return a new object to populate the parts drop down list)
I get the message: Too many characters in character literal on the line
<% =Html.DropDownList("Types") %>
It appears this issue is caused by the javascript being added, but why and why the error is on the previously good line of code in the markup and not in the script?
Thanks in advance.