Solved

Dynamically changing javascript code

Posted on 2016-10-12
2
80 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Suggested Courses

635 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