possible small error, but I can't spot it (IE Doesn't care!!!)

J

J-P-W

Hi,

function Validate()
{
if (document.frmRegister.TermsAgreed.checked)
{
document.all.ShowImages.style.display='block';
document.all.UserHeaderHTML.disabled=false;
document.all.UserFooterHTML.disabled=false;
document.all.ShowText.style.display='block';
document.all.UserHeaderFileName.disabled=false;
document.all.UserFooterFileName.disabled=false;
alert('Development note - while error trapping - this form normally
be submitted now, but actually not for now!');
return false;
}
else
{
alert('You must tick the box to show that you agree to the terms and
conditions.');
return false;
}
}

If the TermsAgreed is not ticked [checked] I get alerted and the form
does not submit.
If I tick [check] it then the various bits of script don't run and the
page submits.......

Unless I'm using IE (7 or 8) Chrome and Firefox refuse to run the code
and just submit the form.

Any thoughts?

Greatful thanks

Jon
 
J

Jeremy J Starcher

Hi,

function Validate()
{
if (document.frmRegister.TermsAgreed.checked)
{
document.all.ShowImages.style.display='block';

document.all.UserHeaderHTML.disabled=false;
document.all.UserFooterHTML.disabled=false;
document.all.ShowText.style.display='block';
document.all.UserHeaderFileName.disabled=false;
document.all.UserFooterFileName.disabled=false; alert ('Development
note - while error trapping - this form normally
be submitted now, but actually not for now!');
return false;
}
else
{
alert('You must tick the box to show that you agree to the terms and
conditions.');
return false;
}
}

If the TermsAgreed is not ticked [checked] I get alerted and the form
does not submit.
If I tick [check] it then the various bits of script don't run and the
page submits.......

Unless I'm using IE (7 or 8) Chrome and Firefox refuse to run the code
and just submit the form.

Any thoughts?

Greatful thanks

Jon

"document.all" is a non-standard property that regarded as IE-only.

document.frmRegister is non-standard as well.

Either use document.getElementById or use the document.form methods to
access the elements.

In addition, be sure to proper server-side checking as well as Javascript
is easy disabled.

In addition, the use of alert for messages to the user is considered by
many to be archaic and crude. Changing the checkbox's label to a red
text or something might be more appropriate.


Read this:
< http://www.mopedepot.com/jjs/HowToRecognizeBadJavascriptCode.html >
 
J

J-P-W

function Validate()
{
           if (document.frmRegister.TermsAgreed.checked)
           {
           document.all.ShowImages.style.display='block';
           document.all.UserHeaderHTML.disabled=false;
           document.all.UserFooterHTML.disabled=false;
           document.all.ShowText.style.display='block';
           document.all.UserHeaderFileName.disabled=false;
           document.all.UserFooterFileName.disabled=false; alert ('Development
           note - while error trapping - this form normally
be submitted now, but actually not for now!');
        return false;
           }
           else
           {
           alert('You must tick the box to show that you agree to the terms and
conditions.');
           return false;
           }
}
If the TermsAgreed is not ticked [checked] I get alerted and the form
does not submit.
If I tick [check] it then the various bits of script don't run and the
page submits.......
Unless I'm using IE (7 or 8) Chrome and Firefox refuse to run the code
and just submit the form.
Any thoughts?
Greatful thanks

"document.all" is a non-standard property that regarded as IE-only.

document.frmRegister is non-standard as well.

Either use document.getElementById or use the document.form methods to
access the elements.

In addition, be sure to proper server-side checking as well as Javascript
is easy disabled.

In addition, the use of alert for messages to the user is considered by
many to be archaic and crude.  Changing the checkbox's label to a red
text or something might be more appropriate.

Read this:
<http://www.mopedepot.com/jjs/HowToRecognizeBadJavascriptCode.html>

Thank you Jeremy, converting all of the document.xxx to
document.getElementById('xxxx')
was spot on.

Regards

Jon
 
O

Osmo Saarikumpu

Jeremy said:

I did and caught a couple of errors. In two consecutive examples the
following line is present:

var j;.
^
Them full stops causing syntax errors.

But you can make use of one of them by moving it to the following string:

"Then when a browser is updated, they will suddenly fail Strictly avoid
any code that falls into one of these traps."

Side note: green background color for good examples was a little
confusing, at least from my cultural background (green to go, red to not).

HTH,
Osmo
 
J

Jeremy J Starcher

I did and caught a couple of errors. In two consecutive examples the
following line is present:

var j;.
^
Them full stops causing syntax errors.

Thanks for catching that. I've got a list of minor changes to make to
that page, but that just bumped the priority up.
But you can make use of one of them by moving it to the following
string:

"Then when a browser is updated, they will suddenly fail Strictly avoid
any code that falls into one of these traps."

Side note: green background color for good examples was a little
confusing, at least from my cultural background (green to go, red to
not).

Thats the other change to make. The color scheme is confusing for
colorblind folks.
 

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

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top