UJ,
cdiv will be null if no DOM element has the id of the variable elid .
Either the value returned by phpScript.php is wrong (it may just need trimming) or it is correct but the div in question is wrongly id'd or doesn't exist at all.
When there is a perfect match between elid and the id of an existing DOM element (hopefully the div you're looking for) then alert(cdiv); should give "[object]"
The code you posted looks fine.
I think the problem must lie elsewhere; either in the php/HTML that (is supposed to have) created the div in question, or the code in phpSctipt.php that (is supposed to) return a valid div id.
By the way ... hi to Ess.Airshow
Airshow
WiFi Lounge Lizard
2,683 posts since Apr 2009
Reputation Points: 321
Solved Threads: 372
UJ,
Burried in my post above is a suggestion that the returned divID might need to be stripped. ie. it may have leading/trailing white space that doesn't show up in a javascript alert.
You can test the theory with alert(divID.length). See if it reports the expected number of characters.
If this turns out to be the problem then you can do one (or both) of two things:Fix the php such that it only returns the necessary string. It's good to put an exit command immediately after printing the required output to ensure nothing gets tacked on further down the page.
Trim the returned string in jvascript. This is a bit tricky if you don't know what to trim off, so method 1 is preferred.
Airshow
Airshow
WiFi Lounge Lizard
2,683 posts since Apr 2009
Reputation Points: 321
Solved Threads: 372
UJ,
With exit doing its thing, I would guess you've got a leading carriage return from somewhere higher up the page. They can creep in if the source code dances <? in and ?> out of php. And check that the opening <? is hard against the top of the file.
Alternatively .....
I'm not sure which style of line feed it might be, so try stripping both the common types:
divID = divID.replace("\n", "");
divID = divID.replace("\r\n", "");
Each statement will remove one line feed so if this still doesn't work do each of the above twice by duplicating the lines.
Good luck.Airshow
Airshow
WiFi Lounge Lizard
2,683 posts since Apr 2009
Reputation Points: 321
Solved Threads: 372
I just read the thread through and spotted UJ's post #12. I must have been a bit bleary-eyed yesterday morning.
Ignore my ramblings above. I'm sure that String.prototype.trim is the way to go.
Airshow
Airshow
WiFi Lounge Lizard
2,683 posts since Apr 2009
Reputation Points: 321
Solved Threads: 372