I have a JQuery Dialog, with a control inside containing textboxes, I also have a save button inside.
On the save click I get the value from the textbox and pass it to a function.
Problem:
Everytime I change the value in the textbox it only gets the old value,
so, if the original value is 2, i change it to 20, i click the button, it gets the value 2.
Anyone have any ideas as to why it does this?
thanks!
here is some code:
JQUERY:
$("#inputupdatecontrol<%=PlantID %>").dialog({
autoOpen: false,
modal: true,
width: 500,
height: 400
});
HTML:
<script type="text/javascript">
function SaveActivityManagementData() {
var plantid = $('.drpplants').val();
var worktype = $('.worktype').val();
var startdate = $('.startdate').val();
var enddate = $('.enddate').val();
var planid = $('.planid').val();
var mob = $('.mob').val();
var assignedto = $("input[name=txtassignedtoid]").attr("value");
var currentuserId = $("input[name=CurrentUserId]").attr("value");
var clientId = $("input[name=ClientId]").attr("value");
AjaxSaveActivityManagementData(plantid, worktype, startdate, enddate, planid, mob, assignedto, currentuserId,clientId);
}
</script>
<table>
<tr>
<td>Plant:</td>
<td><asp:DropDownList ID="drpPlants" runat="server" DataValueField="Id" DataTextField="Name" CssClass="drpplants"></asp:DropDownList></td>
</tr>
<tr>
<td>Work Order:</td>
<td>
<div>
<asp:Label ID="lblExisiting" runat="server" Text="Existing"></asp:Label>
<asp:RadioButton runat="server" GroupName="workorder" ID="rbExisting" Checked="true" />
<asp:DropDownList ID="DropDownList1" runat="server"></asp:DropDownList>
</div>
<div>
<asp:Label ID="Label1" runat="server" Text="New"></asp:Label>
<asp:RadioButton ID="rbNew" runat="server" GroupName="workorder" />
<asp:TextBox ID="txtnew" runat="server"></asp:TextBox>
</div>
</td>
</tr>
<tr>
<td>Work Type:</td>
<td>
<asp:DropDownList ID="DropDownList2" runat="server" CssClass="worktype">
<asp:ListItem Text="non-routine"></asp:ListItem>
<asp:ListItem Text="pilot project"></asp:ListItem>
<asp:ListItem Text="routine"></asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td>Description:</td>
<td><asp:TextBox ID="txtDesc" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td>Start Date:</td>
<td><asp:TextBox ID="txtStartDate" runat="server" CssClass="startdate"></asp:TextBox></td>
</tr>
<tr>
<td>End Date:</td>
<td><asp:TextBox ID="txtEndDate" runat="server" CssClass="enddate"></asp:TextBox></td>
</tr>
<tr>
<td>Plan ID:</td>
<td><asp:TextBox ID="txtPlanId" runat="server" CssClass="planid"></asp:TextBox></td>
</tr>
<tr>
<td>MOB:</td>
<td><asp:TextBox ID="txtMOB" runat="server" CssClass="mob"></asp:TextBox></td>
</tr>
<tr>
<td>Assigned To:</td>
<td>
<asp:TextBox ID="txtAssignedTo" runat="server" CssClass="assignedto"></asp:TextBox>
<input type="text" name="txtassignedtoid" visible="false" class="assignedtoid" style="display:none;" />
<input type="text" name="CurrentUserId" visible="false" class="userid" style="display:none;" />
<input type="text" name="ClientId" visible="false" class="clientid" style="display:none;" />
</td>
</tr>
<tr>
<td></td>
<td><asp:CheckBox runat="server" ID="chkOverRide" Text="Override" /></td>
</tr>
<tr>
<td></td>
<td><asp:DropDownList ID="drpAssignment" runat="server" DataTextField="FirstName" DataValueField="id"></asp:DropDownList></td>
</tr>
<tfoot>
<tr>
<td></td>
<td>
<asp:Button ID="btnSave" runat="server" Text="Save" OnClientClick="SaveActivityManagementData();"/>
<asp:Button ID="btnDelete" runat="server" Text="Delete" OnClick="DeleteClick" />
<asp:Button ID="btnCancel" CssClass="btnFormCancel" runat="server" Text="Cancel" />
</td>
</tr>
</tfoot>
I’ve experienced this before – not with jQuery but with YUI. I believe the
.val()method is prone to returning the value before the change event has propagated – whereas accessing the underlying DOM element’s value directly should work. So instead of:You’d have something like:
You may need to correct that second syntax – I’m not sure that’s the best way of accessing the underlying DOM node in jQuery…