Click here to Skip to main content
15,900,907 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
XML
Hi,
I have Two text boxes which are hide when it's in a list. After Clicking Edit, I would like to show the text boxes visible.
From the below code when I say the text box "visible" it displays accordingly. But I need to show the text boxes when it's in a edit mode.
Please help me how to visible/show when i click the button.
- show the text boxes after i click the "Edit" button
- hide the text boxes after I click the "save" button.
Thanks for reading and help would be great.
@model IEnumerable<NameList>

<script src="~/Scripts/jquery-1.10.2.min.js"></script>

<script type="text/javascript">
function ShowEdit(par) {
$("#divBDate-" + par).attr("class", "hide");
$("#txtBDate-" + par).attr("class", "visible");
$("#divEDate-" + par).attr("class", "hide");
$("#txtEDate-" + par).attr("class", "visible");
$("#btnEdit-" + par).attr("class", "hide");
$("#btnSave-" + par).attr("class", "visible");
}

function SaveEdit(par) {
$("#divBDate-" + par).attr("class", "visible");
$("#txtBDate-" + par).attr("class", "hide");
$("#divEDate-" + par).attr("class", "visible");
$("#txtEDate-" + par).attr("class", "hide");
$("#btnEdit-" + par).attr("class", "visible");
$("#btnSave-" + par).attr("class", "hide");

var -bDate = $("#txtBDate-" + par).val();
var -dDate = $("#txtEDate-" + par).val();
var url = '@Url.Action("GetUser", "Cust")';
$.post(url, { RoleId: par, userId: -userId, startDate: -startDate },
function (data) {
$("#divResult").html(data);
});
}
</script>



<div id=divResult">
<table class="table">
<tr>
<th>Name</th>
<th>Area</th>
<th>Beginning Date</th>
<th>End Date</th>
</tr>

@foreach (NamesList n in Model)
{
<tr>
<td> @n.Name </td>
<td>@n.Area </td>
<td>
<div id="divBDate-@n.ID" class="visible">@n.BDate</div>
<input id="txtBDate-@n.ID type=" text" class="hide" value=@n.BDate />
</td>
<td>
<div id="divEndDate-@n.ID" class="visible">@n.EndDate</div>
<input id="txtEndDate-@n.ID type=" text" class="hide" value=@n.EndDate />
</td>
<td>
<button id="btnEdit-@n.ID" class="visible" onclick="ShowEdit(@n.ID); return false;">Edit</button>
<button id="btnSave-@n.ID" class="hide" onclick="SaveEdit(@n.ID); return false;">Save</button>
</td>

</tr>
}
</table>
</div>
Posted

As I can see, you are using jQuery, which makes by answer easier to write.

When you hide a text box, it cannot be "in edit mode", which simply means having the keyboard focus on it. You just need to focus it:
http://api.jquery.com/focus[^] (focuses when used without an argument).

By the way, showing and hiding can be easier:
http://api.jquery.com/show[^],
https://api.jquery.com/hide[^].

—SA
 
Share this answer
 
Comments
Member 10728605 6-Apr-14 23:24pm    
Sergey, Thanks for the Reply.
I couldn't get from the reference :-(
If you can, please help me with my code.
Thanks.
Sergey Alexandrovich Kryukov 6-Apr-14 23:31pm    
What couldn't you get? Do you know how obtain a DOM object wrapper from a selector? It looks like you can? Can you call a jQuery method on it? It looks like you can. So, what's the problem, exactly?
—SA
Member 10728605 6-Apr-14 23:44pm    
Yes, the problem is I don't know how to use DOM object wrapper from a selector. Just started to use JQuery.
Nga
Sergey Alexandrovich Kryukov 7-Apr-14 0:24am    
You do know that: $("#divBDate-" + par), that's it.
—SA
Member 10728605 7-Apr-14 0:31am    
I do have it in my code, but text boxes are not visible when I click the Edit button.
function ShowEdit(par) {
$("#divBDate-" + par).attr("class", "hide");
}
function SaveEdit(par) {
$("#divBDate-" + par).attr("class", "visible");
}
It's very easy with jquery.

JavaScript
$("#btnSave-" + par).hide();

and
JavaScript
$("#btnSave-" + par).show();
 
Share this answer
 
Comments
Member 10728605 6-Apr-14 23:20pm    
RyanDev, Thanks for the reply.
your code works. But the purpose is when I click the Edit button, button save needs to be displayed and also the text boxes also needs to be visible.
Also if you see my code I do have btnEdit and btnSave which works fine. It means when I click the button edit, button save is visible. All I need is when click the Edit button, text boxes needs to visible along with Save button.
Please help me if you can. Thanks again.
ZurdoDev 7-Apr-14 7:18am    
OK. Where are you stuck? When you click the edit button you need $("#btnSave").show() and $("#txtWhatever1").show() and $("#txtWhatever2").show()

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900