Solved

Dynamically changing javascript code

Posted on 2016-10-12
2
76 Views
Last Modified: 2016-10-12
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
Comment
Question by:Brian Coughter
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 43

Accepted Solution

by:
zephyr_hex (Megan) earned 500 total points
ID: 41840758
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
 

Author Closing Comment

by:Brian Coughter
ID: 41841106
Excellent.  I was way over thinking that.  Thank you!
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Angular tyeahead feature not working with Control "as" ControlXXX 4 50
Conformation code 4 36
Json and ajax javascript 24 23
Javascript function 3 20
This article discusses how to create an extensible mechanism for linked drop downs.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question