Search code examples
javascriptjqueryconditional-statementsdynamic-html

Conditional HTML need suggestion


What will be better of these 2 cases. Just making sure I am using best practice.

<% if(isEdit){ %>
<input type="text" id="tabtitle" name="title" value=<%=Content%>/>
<%}else{%>
<input type="text" id="title" name="title"/>
<%}%>

OR

 $(document).ready(function() { 
<% if(isEdit){ %>
   $("#title").val("<%=Content%>");
<%}%>
});

Solution

  • The second uses JavaScript / JQuery to modify the element. Since adding client-side code has no advantage I would take the first approach which is server-side only. Although without seeing the bigger picture it's hard to endorse this approach particularly either.