473,387 Members | 1,321 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 2800
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jan-Henrik Grobe | last post by:
Hallo, I am coming to this newsgroup with a very strange Problem. I have two c++ files A.cpp and B.cpp....In A.cpp I am creating an openGL window and in B.cpp I have stored the callback...
3
by: kimi | last post by:
Hello, yes i try to learn c-programming.So i have a question on my code, but if i am wrong here please tell me a group where i belong to. I wrote a function which fgets a filename from the...
12
by: effendi | last post by:
I wrote the following function and tested it in MSIE, Firefox and Mac Safari, Works in all but the Safari. What can I do to rectify this? function processBackground(){ for (n=1;n<11;n++) { ...
2
by: petermichaux | last post by:
Hi, It seems like determining element position in a web page is a difficult task. In the position reporting source code I've looked at there are special fixes for at least some versions of...
16
by: deepres | last post by:
Hi, I have the following problem. In my application I'm dynamically replacing some of web-page content. For example, I have something like that: <span id="ui_tr_22_1_treeJ_span" > <div...
2
bilibytes
by: bilibytes | last post by:
Hi, i have been creating an ajax aplication on my website and it worked as i expected it to work on Safari and Firefox, until i upgraded to Firefox 3. It doesn't work either on windows. the...
2
by: panos100m | last post by:
Hi on page load a javascript functions (timedCount()) is executed (timer) which executes another javascript function (ajax function:findprov(divtowrite) ) in turn this calls a php file to query a...
10
by: Kenny | last post by:
Noob here. I have incorporated the jquery ui tab control in my web app. It works Ok but the page comes up un-tabbed and then flashes into the desired tab setup. The tabs capability gets in via:...
53
by: souporpower | last post by:
Hello All I am trying to activate a link using Jquery. Here is my code; <html> <head> <script type="text/javascript" src="../../resources/js/ jquery-1.2.6.js"</script> <script...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.