ef*****@epitome.com.sg wrote:
Hi
I tested the following function in Safari and it doesnt work. This is
tested fine in IE.
"Doesn't work" is a useless description. What did you expect to happen?
What did happen? What error message(s) did you get?
function processOutcome(){
mainDatabase=document.forms[0].AssessDatabase.value
Is mainDatabase supposed to be a global variable? If not, keep it local
with var, otherwise declare it in the global space (with var) so it's
obvious that it's supposed to be global.
var oCheckboxs=document.forms[0].TeamID
if (oCheckboxs=="undefined" )
The above statement will *always* evaluate to false, therefore this
block will never be executed and the else block always will.
When you have more than one checkbox named TeamID, Safari barfs at
trying to evaluate the value of 'oCheckboxs' (it gives an error message
'No default value').
Perhaps you meant:
if (typeof oCheckboxs == "undefined")
Which fixes your problem with Safari and is much better syntax.
{alert ("No Teams has been formed")}
Or "No Teams have been formed". ;-)
else {
var ClassNo=document.forms[0].ClassSection.value
oCheckboxs = ('undefined' != typeof oCheckboxs[0]) ?
oCheckboxs : [oCheckboxs];
var sReturn="";
for (var i=0;i<oCheckboxs.length;i++){
if (oCheckboxs[i].checked)
if (sReturn=="")
sReturn=oCheckboxs[i].value;
else
sReturn=sReturn+","+oCheckboxs[i].value;
}
A much simpler for loop is:
for (var i=0; i<oCheckboxs.length; i++) {
if (oCheckboxs[i].checked) {
sReturn += oCheckboxs[i].value;
}
}
>
if (sReturn=="") {
alert("Select a team for Outcome Assessment"); }
else {
window.location="/"+mainDatabase+"/outcome?openform&ClassSection="+ClassNo+"&TeamID="
+sReturn}
}}
What did I do wrong?
It makes it much easier to help you if you:
- always add braces {} in block unless you keep them on one line,
- properly block and indent your code
- always add semi-colons at the end of statements
- use 2 spaces for indented code
- post an example that actually demonstrates the issue, rather than
leaving others to fill in the missing bits, possibly guessing
wrongly for some of it
--
Rob