469,270 Members | 1,123 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,270 developers. It's quick & easy.

Function doesnt work in Safari -

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[i].checked)
if (sReturn=="")
sReturn=oCheckboxs[i].value;
else
sReturn=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?

Oct 17 '06 #1
2 2664
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
Oct 17 '06 #2

RobG wrote:
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

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

Oct 17 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Jan-Henrik Grobe | last post: by
12 posts views Thread by effendi | last post: by
10 posts views Thread by Kenny | last post: by
53 posts views Thread by souporpower | last post: by
1 post views Thread by CARIGAR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.