Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 95
  • Last Modified:

Dynamically changing javascript code

I have a <div> that contains a date:

<div id="editDateDiv">10/20/16</div>

Open in new window


I want to grab that date and update the date on line 5 of the following jQuery code upon clicking a <td>:

$("#addNew").on("mouseup", function() {
     $(this).css("background", "white");
     $(this).css("color", "#008bab");
     $("#editDateDiv").html("Add New...");
     $("#currentAppts").load("calendar_appNew.cfm?appDate=10/12/2016");
});

Open in new window


How can I accomplish this?
0
Brian Coughter
Asked:
Brian Coughter
1 Solution
 
zephyr_hex (Megan)DeveloperCommented:
You can get the date from the field on click of the td, and then assign that date to a globally scoped variable.

var dateToUse = "";
$('td').on('click', function() {
   dateToUse = $('#editDateDiv').text();
});

$("#addNew").on("mouseup", function() {
     $(this).css("background", "white");
     $(this).css("color", "#008bab");
     $("#editDateDiv").html("Add New...");
     $("#currentAppts").load("calendar_appNew.cfm?appDate=" + dateToUse);
});

Open in new window


Some caveats:
  • the date you're showing in editDivDate is not the same format as the date you're using the appDate url parameter.  So, you will probably need to adjust the format before using it in the appDate url parameter.
  • You should verify that the editDivDate contains a valid value before using it as the appDate url parameter value.  I.E.  verify the value is a properly formatted date and not an empty string or malicious code
0
 
Brian CoughterOwnerAuthor Commented:
Excellent.  I was way over thinking that.  Thank you!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now