I dont understand why the following code is not working. I save some inputs values to sessions. In the next page, I want users be able to copy these values to input fields.
$(function() {
$(“input#copyshipping”).click(function(){if ($("input#copyshipping").is(':checked')) { // Checked, copy values $("input#BillingFirstName").val("<%=Session("ShippingFIRSTNAME")%>"); $("input#BillingLastName").val("<%=Session("ShippingLASTNAME")%>"); $("input#BillingAddress1").val("<%=Session("ShippingADDRESS1")%>"); $("input#BillingAddress2").val("<%=Session("ShippingADDRESS2")%>"); $("input#BillingCity").val("<%=Session("ShippingCITY")%>"); $("input#BillingState").val("<%=Session("ShippingSTATE")%>"); $("input#BillingCountry").val("<%=Session("ShippingPOSTALCODE")%>"); $("input#BillingPostalCode").val("<%=Session("ShippingCOUNTRY")%>"); } else { // Clear on uncheck $("input#BillingFirstName").val(""); $("input#BillingLastName").val(""); $("input#BillingAddress1").val(""); $("input#BillingAddress2").val(""); $("input#BillingCity").val(""); $("input#BillingState").val(""); $("input#BillingCountry").val(""); $("input#BillingPostalCode").val(""); } }); });
Looking at the source code, it appears that the textboxes do not have id attributes, only name attributes. When you say, for example,
$("input#BillingFirstName"), the “#” indicates an ID, and there isn’t one there.Either add an id, or use
$("input[name='BillingFirstName']). I recommend adding the id; it’s a faster selector.