04-08-2008, 13:50
|
#1
|
|
cf.mega poster
Join Date: Oct 2003
Location: Portsmouth
Age: 30
Posts: 1,686
|
javascript null error
Hello peeps,
Yeasterday I posted about my near identical ubuntu servers and a strange charecter encoding problem.. well today I am having a javascript error that occurs on my live server and not on the local server... everything works fine on the local server, but on the remote server it falls over and Firebug reports the following:
Code:
document.getElementById("modelId") is null
the code that is returning this is:
Code:
var modelId = document.getElementById('modelId').value;
so i tried this:
Code:
if (document.getElementById('modelId').value == null) {
var modelId = 1
}else{
var modelId = document.getElementById('modelId').value;
}
to no avail...
If anyone could help i would ve really apreciateive!
Last edited by Millay; 04-08-2008 at 13:59.
Reason: spelling worked 27 hours without a break
|
|
|
04-08-2008, 13:53
|
#2
|
Join Date: Jul 2003
Location: Poole, Dorset
Age: 23
Services: Sky+
V-Box
VM 10MBit
Posts: 10,108
|
Re: javascript null error
But the PHP Pre-processor shouldn't be touching any of the code so I don't see how that would make sense?
|
|
|
04-08-2008, 14:00
|
#3
|
|
cf.mega poster
Join Date: Oct 2003
Location: Portsmouth
Age: 30
Posts: 1,686
|
Re: javascript null error
Sorry graham excuse my ignorance, but i cant see how php pre-processor is involved??
|
|
|
04-08-2008, 14:00
|
#4
|
Join Date: Jul 2003
Location: Poole, Dorset
Age: 23
Services: Sky+
V-Box
VM 10MBit
Posts: 10,108
|
Re: javascript null error
Well you say it works fine on one server and not on another, is the extension of the file .php or?
|
|
|
04-08-2008, 14:05
|
#5
|
|
cf.mega poster
Join Date: Oct 2003
Location: Portsmouth
Age: 30
Posts: 1,686
|
Re: javascript null error
sorry yes it is a php file so yes it is going through the php preprocessor, which makes me wonder if it has something to do with:
Code:
<script language="javascript">populatevanModels('<?php echo $_POST['modelId']; ?>');</script>
<script language="javascript">setTimeout("populatevanDerivatives('<?php echo $_POST['derivativeId']; ?>')",500);</script>
but the strange thing is only the servers have changed al lthe data and backend databases are the same..
|
|
|
04-08-2008, 14:55
|
#6
|
|
cf.geek
Join Date: Jan 2004
Posts: 993
|
Re: javascript null error
are you running the js before or after the DOM has fully loaded?
|
|
|
04-08-2008, 15:26
|
#7
|
|
A tired software engineer
Join Date: Jun 2003
Location: SK10
Posts: 92
|
Re: javascript null error
Not really a webby person, so I can't help with why it works on one server but not the other, but shouldn't your code work-around be:
Code:
if (document.getElementById('modelId') == null) {
var modelId = 1
}else{
var modelId = document.getElementById('modelId').value;
}
|
|
|
04-08-2008, 15:44
|
#8
|
Join Date: Jul 2003
Location: Poole, Dorset
Age: 23
Services: Sky+
V-Box
VM 10MBit
Posts: 10,108
|
Re: javascript null error
Also try a semi-colon after var modelId = 1
|
|
|
05-08-2008, 02:27
|
#9
|
|
cf.addict
Join Date: Jul 2004
Posts: 295
|
Re: javascript null error
Check that document itself isn't null...
var modelId = null;
if (document != null) {
if (document.getElementById('modelId') == null) {
modelId = 1;
}else{
modelId = document.getElementById('modelId').value;
}
} else {
modelId = 1;
}
|
|
|
05-08-2008, 07:39
|
#10
|
|
cf.mega poster
Join Date: Oct 2003
Location: Portsmouth
Age: 30
Posts: 1,686
|
Re: javascript null error
Im almost out of ideas, i tried all your tips, still to know joy.. any ideas greatly apreciated.
|
|
|
05-08-2008, 08:38
|
#11
|
Join Date: Jul 2003
Location: Poole, Dorset
Age: 23
Services: Sky+
V-Box
VM 10MBit
Posts: 10,108
|
Re: javascript null error
Could you paste the rest of the code where the modelID input is Millay>
|
|
|
05-08-2008, 21:19
|
#12
|
|
cf.mega poster
Join Date: Oct 2003
Location: Portsmouth
Age: 30
Posts: 1,686
|
Re: javascript null error
Hi graham and everyone else who helped.
I fixed the problem, it was caused by php code, and some ajax stuff.
I feel silly for posting but apreciate all the help..
Its one of those things you work for 20+ hours straight and you cant see the wood for the trees!
---------- Post added at 22:19 ---------- Previous post was at 22:16 ----------
New we should have used a CVS system..
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT. The time now is 10:29.
|