PopulateOnLoad Cross Browser Problem

Hi

I have a website http://www.bristolstreet.co.uk/ that has a car search box functionality which uses an external javascript file to populate the makes and models within the dropdown boxes.

A few weeks ago I realised that it didn’t work in safari (initilly I had the populate onload code attached to the submit image), I then moved the code into a inline script tag and it worked but now i’ve realised it doesn’t work in Firefox… I am now thinking of adding a script to determine the browser and dynamically work on adding the populate code depending on the browser but thought it would be a good idea to post on here in case there is an overall much better solution. If you visit the site you will see a working example of the issue.

Any help would be great.

Regards
Rachel

Where-abouts is veh_srch defined?

Currently you are using it as if it were a global variable, but it doesn’t currently exist.
I presume that you’re wanting to refer to a form instead?

The name attribute on the form is considered to be an inelegant way of referring to page elements. Long ago when HTML 4 was being created, it was deemed that unique identifiers should be preferred over the name attribute. The name attribute should only be used to identify individual form elements.

If your form was identified as follows:


<form id="veh_srch" method="post">

You could then associate the javascript variable veh_srch with the form by using:


var veh_srch = document.getElementById('veh_srch');

These script parts need to occur after the form, at a minimum. Preferable is to have the script just before the </body> tag, but it’s also acceptable to instead use an onload event.

Since using inline event attributes is considered to be a big no-no when it comes to associating elements with events, this could also be a good time to associate a function with the onsubmit event of the form.


veh_srch.onsubmit = function () {
    return SubmitSearch(this);
}

Since the form is the element that triggers the onsubmit event, the this keyword will refer to the form itself.

Thank you very much, you are a star - it now works and I will make it priority to learn best practice and implement the preferred solution in the very near future.

Rachel