Javascript only works if I refresh the page

david k

New Member
Sorry if this has already been posted, I couldn't find it anywhere

Got a strange problem with my element javascript.

I have 2 forms and 2 groups. First form points to the second assuming the user agrees to a disclaimer. This works fine. Initially I write my own script and had the 2 groups on the same page, hiding and showing the relevent part of the form, but the Javascript worked erratically so I split it up. The 'submit' button now does all the work and this works fine.

The main form is still erratic though. This is what happends.

First use of the form. The javascript may or may not run. (javascript for date fields always work). Using the form again it rarely works. If you refresh the page it usually works.

The javascript in question is attached to a button which does a simple calculation, but I don't think the javascript is the problem. This is because when I had two buttons on the same form they either both worked or neither worked.

The first form (that leads to the second is on
http://www.alpineskiclub.org.uk/component/option,com_fabrik/Itemid,58/

Has anyone seen this behaviour before?

Best Regards
David
 

Attachments

  • script.js
    2.4 KB · Views: 358
Hi david

For me, in firefox I get a javascript error when i click on the button

Code:
syntax error
[Break on this error] ath.ceil((HireDays-InitialHireDays)/7));HirePeriods = 1 + ExtraWeeks};else{HireP...

at a rough guess id say that

Code:
if((HireDays)>(InitialHireDays))
{
ExtraWeeks = (Math.ceil((HireDays-InitialHireDays)/7));
HirePeriods = 1 + ExtraWeeks
}

;
else
{
HirePeriods = 1;
ExtraWeeks = 0
}

should be

Code:
if((HireDays)>(InitialHireDays))
{
ExtraWeeks = (Math.ceil((HireDays-InitialHireDays)/7));
HirePeriods = 1 + ExtraWeeks
}
else
{
HirePeriods = 1;
ExtraWeeks = 0
}
 
Thanks for the reply Rob.

Actually looks like I have 2 problems.
Firefox seems to chuck up the issue you are seeing
IE is bugging out another

IE Issue
I did a diff on the working and non-working source and found the following difference

Working
<input type='hidden' name='_cursor' value='0' id = '_cursor' />
<input type='hidden' name='_total' value='0' id = '_total' />
Not Working
<input type='hidden' name='_cursor' value='Array' id = '_cursor' />
<input type='hidden' name='_total' value='Array' id = '_total' />

Notice that value has gone from '0' to 'array'. Strange that this would be affected by a refresh. Any Ideas?

Firefox

Tried what you suggested and got another failure

fabrik1 is not defined
eval(js) ;

David
 
JavaScript is notoriously finicky about what is in scope where, and how you specify the full DOM path of any given entity. In this case, where the JS gets eval'ed, there is no such thing as 'fabrik1' (it'd prolly be something like window.document.fabrik1, or some such).

Which is why Mootools makes things so much easier. So try using mootools selectors, so instead of (for example)

Code:
var Meet = fabrik1.asc_transceiver___elmeet.value;

... do ...

Code:
var Meet = $('asc_transceiver___elmeet').value;

By using the mootools selector, it'll work anywhere on the page, in any context.

-- hugh
 
I have also had problems with mootools not loading completely and having to refresh the page to get mootools to run it's scripts properly.
 
Fantastic, that's half the problem solved. Now I'm just stuck with the IE one, which I think has to do with the 'Array' issue.
I'll keep looking but if anyone has nay ideas.....

Thanks again Hugh on the help so far.

David K
 
Hi

@Andre

depending on the script you are using, you may need to encase it within this (esp if the script runs when the page loads):

Code:
document.addEvent('domready', function(){
.....
});

this waits for the DOM to load, and ensures that the dom elements are available for your script to access.

@david

The array thing looks like a little bug, but wont effect the javascript. By the way looking at your page now the js seems to work, can you confirm that?

Cheers
Rob
 
Rob

Yes the javascript does work. With non-IE browsers in fact the code seems to work perfecty. I tried your fix but alass to no avail, I don't even think it gets as far as trying to run the script (only a guess but when I had other scripts in the same page, none or all of them worked).

Anyway, very pleased with progress so far. Thanks for everyones help.

David
 
All

Still seeing the erratic problem of the javascript not working in IE sometimes. Additional information from a friend suggests a similar issue with Safari.

This only noticable difference in the source is the 'array' vs. '0' issue posted earlier. If the 'Array' is i the source it just won't work. I don't know if I'm it is the cause or a symptom.

David

PS Rob, I tried you suggestion with the document.addEvent('domready', function(){ but without joy
 
Hi david

Can you try updating to the latest SVN to see if that helps - I think I've fixed the "array" issue. But i still cant replicate the js error you are getting

Cheers
Rob
 
Rob

To reproduce....

Using IE 7 or Safari (not Mozilla)

1) Enter website http://www.alpiineskiclub.org.uk
2) Left hand menu click transceiver hire
3) Click sub menu Transceiver Hire form
4) Select statement I agree....
5) Click button continue to hire transceivers
6) Click Calculate hire Cost
7) Result should be a pop up box with information (javascript works as intended, but it 'might' fail and no pop up box appears.
8) Repeat stages 3 - 6
9) Result, form does not calculate, no pop up, javascript does not run.

I tried the latest versions of Joomla 1.0.4RC with Fabrik 1.0.4 on another site

http://i-83-67-16-250.freedom2surf.net/1point4/

With similar results
 
OK I can repliacte in IE when following your instructions, but the site http://i-83-67-16-250.freedom2surf.net/ doesnt look like it has the latest SVN still.

on it you have :
<input type='hidden' name='_total' value='Array' id = '_total' />

and this has been changed to
<input type='hidden' name='fabrik_total' value='Array' id = 'fabrik_total' />

can you pm me with ftp details to that site so I can mess around to find out whats going on?
 
Rob

ftp://83.67.16.250
user: *******
pssd: ********

NB this will not work in passive mode. Sorry if it's a bit slow but it's my server at home.

PS site is web/1point4/

Thanks a lot

(rob - i just hid the username and pw - best not to leave that lying around on a forum !) - will look now at the site
 
ftp account wont let me alter the fabrik files - can you PM me a superadmin username/password -that way i can use joomlaexplorer to get round the owner issues
 
ok fixed the array rather than 0 isuse but as I thought that wasnt the problem

I've messed around with the code that assigns the javascript events and it appears to be working better now - can you test and confirm if thats the case.
I havent committed the changes Ive made to this site to the SVN yet so if its working for you and you want to put it on your live site, copy the files in components/com_fabrik from the test to the live site

Cheers
Rob
 
Rob et al.

Thought this was a great fix but then I started getting this error didn't dispatch event....... see attached.
Bugger, I really thought it was sorted. I'll do some more testing to see if I can nail some more details.

David
 

Attachments

  • error.bmp
    45.4 KB · Views: 365
  • error.bmp_thumb
    5.2 KB · Views: 356
darn it!
I cant access your site to test further at the moment
I put that alert in there as some kind of feedback about the fact the event wasnt attached to the button
any chance you can put the site back online?

Rob
 
Sorry Rob

Back up and running again. My girlfriend makes me turn it off at night and I forgot to turn it back on again!

David
 
right this time i do think i have fixed it

its a horrid horrid hack that really shouldn't have to be there, but it works :)
Basically if it can attach the event when the form loads, it creates a periodical javascript event which periodically tries to attach the events to the elements.

tested on
mac safarai v2
pc IE7
pc firefox 3beta

let me know if it works for you

Cheers
Rob
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top