Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Don't use XHTML, which isn't well-supported yet (I'm presuming it's actually pseudo-XHTML [being sent with a text/html MIME type], unless you've decided to drop support for IE), and don't use Transitional DOCTYPEs, which are outdated.Unnecessary, and would cause the whole script to be ignored were you using true XHTML (with an XML- or XHTML-based MIME-type). You should almost certainly be sending HTML 4.01 Strict:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
Code:
function changeDropDownSelection(formName,selectionName,i)
Are the first two parameters names, or IDs? The identifiers suggest that they're names, but you've later called document.getElementById() on them, which only takes IDs (according to the standard; Internet Explorer has a bug which causes it to return elements with that name as well, but this is against the standard).
Code:
selectedForm=document.getElementById(formName);
It would be easier and better-supported to use the document.forms collection, but that's less than vital.
Code:
selectedMenu=document.getElementById(selectionName);
Using IDs for form elements, however, is usually a bad idea, since you have to give them a name anyway in order for them to be submitted.
Code:
document.selectedForm.selectedMenu.options[i].selected = true;
Use the document.forms and form.elements collections, don't expect them to be properties of their parent elements. This won't always be the case. Also, there are no elements called "selectedForm" or "selectedMenu" in the markup you've posted here.Return what? Using a blank return statement at the end of a function is pointless -- it will return anyway once control moves out of the function.
Code:
function changeSelect(frmName, elName, index) {
document.forms[frmName].elements[elName].selectedIndex = index;
}
Code:
<a href="javascript:changeDropDownSelection('formatta','imageSelection',5)">Click this link to change to the Battle Rifle Headshot</a>
Firstly, this won't change to the Battle Rifle Headshot, it will change to the Rambonian Owning, since arrays and collections are zero-based in ECMAScript. Secondly, <a> elements with the href attribute are for hyperlinks: that is, links that direct the browser to another page when clicked. IE in particular does things based on this assumption, such as stopping animated images when the link is clicked. If you want to achieve a link-like look (there's a tongue-twister), using a <span> and styling it using CSS is the correct way to go:
Code:
<style type="text/css">
span.pseudolink {
/* Change to match your site's style for links. */
text-decoration: underline;
color: blue;
cursor: pointer;
/* We also only want these to show if the user
has scripting support enabled. */
display: none;
}
</style>
<script type="text/javascript">
onload = function() {
for(var i = 0, e = document.getElementsByTagName("span"); i < e.length; ++i)
if(e[i].className === "pseudolink")
e[i].style.display = "";
};
</script>
Code:
<span class="pseudolink" onclick="changeSelect('formatta', 'imageSelection', 4);">Click here to change to the Battle Rifle Headshot.</span>
You could also use a button.Using a <br> element to force whitespace is an abuse of the element. Use the CSS margin or padding properties.
Bookmarks