Function doesnt work in Safari -

E

effendi

Hi

I tested the following function in Safari and it doesnt work. This is
tested fine in IE.


function processOutcome(){
mainDatabase=document.forms[0].AssessDatabase.value
var oCheckboxs=document.forms[0].TeamID
if (oCheckboxs=="undefined" )
{alert ("No Teams has 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.checked)
if (sReturn=="")
sReturn=oCheckboxs.value;
else
sReturn=sReturn+","+oCheckboxs.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?
 
R

RobG

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.checked)
if (sReturn=="")
sReturn=oCheckboxs.value;
else
sReturn=sReturn+","+oCheckboxs.value;
}


A much simpler for loop is:

for (var i=0; i<oCheckboxs.length; i++) {
if (oCheckboxs.checked) {
sReturn += oCheckboxs.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
 
E

effendi

RobG said:
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.checked)
if (sReturn=="")
sReturn=oCheckboxs.value;
else
sReturn=sReturn+","+oCheckboxs.value;
}


A much simpler for loop is:

for (var i=0; i<oCheckboxs.length; i++) {
if (oCheckboxs.checked) {
sReturn += oCheckboxs.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

I retested the code and it seems this line is not working.


if (oCheckboxs=="undefined" )

I think your solution


if (typeof oCheckboxs == "undefined")


Should solve the problem.

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,782
Latest member
ThomasGex

Latest Threads

Top