Note that there are some explanatory texts on larger screens.

plurals
  1. POTrouble with jQuery selector using ASP.NET MVC
    text
    copied!<p>I'm new to both ASP.Net MVC and jQuery and what I'm trying to do is make a form that either adds a new RockBand or updates an existing RockBand based on if the rockbandid is an empty guid or not. I figured now is a good time to get rolling with jQuery. So the first step is to make a list of bands and put an edit link next to it. If the user clicks on the edit link I want to alter the value of the input box and the hidden field. The code below is the first step, trying to set the value of the input box (with a fixed string for the moment but eventually would be whatever the band name is). However I get an Object Required Error when I do so. (The jQuery include is on the Site.Master)</p> <pre><code>&lt;asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server"&gt; &lt;script type="text/javascript"&gt; function fillinbandname(thebandname) { $('#bandname').val(thebandname); } &lt;/script&gt; &lt;ul&gt; &lt;%foreach (DomainModel.RockBand rockband in ViewData.Model) %&gt; &lt;%{ %&gt; &lt;li&gt;&lt;%=rockband.BandName %&gt; &lt;a href='javascript:fillinbandname("somesamplevalue");'&gt;edit&lt;/a&gt;&lt;/li&gt; &lt;%} %&gt;&lt;/ul&gt; &lt;%Html.BeginForm("MakeOrUpdateRockBand", "Bands", FormMethod.Post); %&gt; &lt;input type="text" id="bandname" name="bandname" maxlength="30" /&gt; &lt;input type="hidden" id="bandid" name="bandid" value="00000000-0000-0000-0000-000000000000" /&gt; &lt;input type="submit" value="Add New Band" /&gt; &lt;%Html.EndForm(); %&gt; &lt;/asp:Content&gt; </code></pre> <p>It feels like I'm soooo close...but am missing something fundamental.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload