function addTimeRange(from,to) {
var tstampFrom;
var tstampTo;
arrFrom = from.split(":");
arrTo = to.split(":");
if (document.serviceAdd.servTimeFromM.options[document.serviceAdd.servTimeFromM.selectedIndex].text == "pm") { (arrFrom[0] += 12); }
if (document.serviceAdd.servTimeToM.options[document.serviceAdd.servTimeToM.selectedIndex].text == "pm") { (arrTo[0] += 12); }
tstampFrom = arrFrom[0]+':'+arrFrom[1]+':00';
tstampTo = arrTo[0]+':'+arrTo[1]+':00';
var opt = document.createElement("option");
opt.text = from+document.serviceAdd.servTimeFromM.options[document.serviceAdd.servTimeFromM.selectedIndex].text+' - '+to+document.serviceAdd.servTimeToM.options[document.serviceAdd.servTimeToM.selectedIndex].text;
opt.value= tstampFrom+' - '+tstampTo;
document.getElementByID("servTimeRange").options.add(opt);
}
Problem is just on the last line of the last group of code here, giving me the "object does not support this property or method" message - and it looks right to me, so probably needs a fresh pair of eyes.
I've also noticed that on the line "arrFrom[0] += 12", that despite the value in this array is a number, it's concatenating it - what's the best way to convert that value to an integer?
Thanks all,
Jess.
06-29-2009, 05:12 AM
Jester
Hi again,
Still not having any luck, but narrowing it down a little... Someone able to point out my fault?
Code:
function addTimeRange(from,to) {
var vlist = document.getElementByID("servTimeRange");
var tstampFrom;
var tstampTo;
arrFrom = from.split(":");
arrTo = to.split(":");
if (document.serviceAdd.servTimeFromM.options[document.serviceAdd.servTimeFromM.selectedIndex].text == "pm") { (arrFrom[0] += 12); }
if (document.serviceAdd.servTimeToM.options[document.serviceAdd.servTimeToM.selectedIndex].text == "pm") { (arrTo[0] += 12); }
var opt = document.createElement("OPTION");
opt.text = optText
opt.value= optValue
vlist.options.add(opt);
//var optRange = new Option(optText, optValue);
//document.getElementByID("servTimeRange").options.add(opt);
}
The same error is now at the first line of this function, so it's very weird... Or is it, can someone say?
Thanks,
Jess.
06-29-2009, 06:02 AM
Malgrim
The Method is called "getElementById" not "getElementByID". Besides, you seem to have set only a name-Attribute in yout HTML, not an id-Attribute.
06-29-2009, 06:10 AM
Jester
Malgrim, Thank you!! The case-sensitivity was all it was.
Yeah, I've been confused by the method before as I've been able to use it on objects without an ID attribute... The name has always sufficed for me before.