JQuery: I have a unique id for my form. How do I use that to select the element ids within it? -


i have form , generate unique id it. idea if more 1 form generated, duplicate ids on each form not interfere each other because can reference unique form id first. want know syntax doing this. on following view, have jquery script reference date field , couple of checkboxes. written, create more 1 form, id nullableotherleavedate, morningonlyflag, afternoononlyflag duplicated. need prefix them unique formid.

<%@ control language="c#" inherits="system.web.mvc.viewusercontrol<shp.models.employeeotherleaf>" %> <% var unique = datetime.now.ticks.tostring(); %> <script language="javascript" type="text/javascript">     $(document).ready(function () {         $('#nullableotherleavedate').datepicker({ dateformat: 'dd-mm-yy' });         $('#morningonlyflag').click(function () {             $('#afternoononlyflag').attr('checked', false);         })         $('#afternoononlyflag').click(function () {             $('#morningonlyflag').attr('checked', false);         })     });      var options = {         target: '#frmaddabsenceoneday<%= unique %>',         success: refreshlist     };      $(document).ready(function () {         $('#frmaddabsenceoneday<%= unique %>').ajaxform(options);     });  </script>  <div id="addabsenceonday<%= unique %>">      <% using (html.beginform("addabsenceoneday", "employee", formmethod.post,            new { id = "frmaddabsenceoneday" + unique }))        { %>         <%: html.validationsummary(true) %>         <fieldset>             <legend>add absence day or half day</legend>             <table>                 <tr>                     <td><%: html.labelfor(model => model.otherleaveid)%></td>                     <td>                 <%: html.dropdownlistfor(model => model.otherleaveid, model.selectleavetypelist, "<--select-->")%>                 <%: html.validationmessagefor(model => model.otherleaveid)%>                                         </td>                 </tr>                 <tr>                     <td>                 <%: html.labelfor(model => model.nullableotherleavedate)%>                                         </td>                     <td>                 <%: html.editorfor(model => model.nullableotherleavedate)%>                 <%: html.validationmessagefor(model => model.nullableotherleavedate)%>                 <%if (viewdata["errordatemessage"] != null && viewdata["errordatemessage"].tostring().length > 0)                   { %>                                       <p class="error">                    @ <% response.write(datetime.now.tostring("t")); %>. <%: viewdata["errordatemessage"]%>.                 </p>                 <%} %>                                      </td>                 </tr>                 <tr>                     <td>                 <%: html.labelfor(model => model.morningonlyflag)%>                     </td>                     <td>                 <%: html.checkboxfor(model => model.morningonlyflag)%>                 <%: html.validationmessagefor(model => model.morningonlyflag)%>                                             </td>                 </tr>                 <tr>                     <td>                 <%: html.labelfor(model => model.afternoononlyflag)%>                     </td>                     <td>                 <%: html.checkboxfor(model => model.afternoononlyflag)%>                 <%: html.validationmessagefor(model => model.afternoononlyflag)%>                                          </td>                 </tr>             </table>              <p>                 <span style="padding-right:10px;"><input type="submit" value="create" /></span><input type="button" value="close" onclick="closetab()" />             </p>         </fieldset>      <% } %>     </div> 

i echo else saying. ids need unique.

for completeness, can pull ids in manner suggest:

<div id="one">    <div id="three">         hello1    </div> </div> <div id="two">    <div id="three">         hello2    </div> </div>  ...  alert($("#one #three").html()); alert($("#two #three").html()); 

http://jsfiddle.net/fn7xs/

but, wouldn't. use class suggested elsewhere.


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -