Call us

Javascript - remember your quotes

General News 1 comment

Yesterday, I was working on my CRM application. To cut a long story short I have upgraded the whole system, added new features and made the whole user experience better.

One of the things I was doing was adding AJAX functionality to perform certain tasks on pages without having to reload the page each time.

Now, I’ll admit that I’m not a Javascript guru but I get by…..almost. Here was my dilemma.  I was using a Javascript “onclick” event to pass a variable into the AJAX routine but for the life of me I couldn’t get it to work. I tried everything (or so I thought) but it just wasn’t happening.

Then, after going and working on something else for a while I came back and found the answer. This will be a no-brainer for you Javascript guru’s out there, but sometimes the smallest things get overlooked. Basically I didn’t put single quotes around the variable that I was passing to the script. Here’s what I mean.

Say my Javascript function was something like:

function displaytimesheet(thedate) {
var date = thedate  ;
var project = document.getElementById(’id’).value  ;
if(date !== “”) {
elem = document.getElementById(’calendarresult’).style;
elem.display = ‘inline’;
………………………. etc

And the onclick event passing this variable was:

….onclick=”displaytimesheet(variable here)”…..

I missed out the bold single quotes above! Just goes to show that sometimes the simple things get overlooked and taking a break and coming back to a problem can be like a fresh pair of eyes looking over it!

I’ve often left a problem overnight and in the morning the solution stands out like a sore thumb!

Related Posts

One Response to “Javascript - remember your quotes”

  1. » Stupid mistake - easy to overlook Says:

    [...] found out the hard way when doing something stupid in Javascript a few weeks ago as [...]

Leave a Comment