javascript error...
-
ok so i have a form that has a droplist in it when the selection changes i want to fire the submit event so i add this: <form name='fp' method='post' action='blah.blah'> <select name='fptype' onChange='document.fp.submit()'> --- rest of form --- </form> and all i get is errors saying: document.fp.submit is not a function am i being an idiot or did something change when i wasnt looking? :wtf:
-
ok so i have a form that has a droplist in it when the selection changes i want to fire the submit event so i add this: <form name='fp' method='post' action='blah.blah'> <select name='fptype' onChange='document.fp.submit()'> --- rest of form --- </form> and all i get is errors saying: document.fp.submit is not a function am i being an idiot or did something change when i wasnt looking? :wtf:
uhm, I tried the exact code you described and it worked for me (in IE that is). Are you using a different browser? As reference though, this is a more programatically correct approach:
<!--
function onchangeOptions()
{
var frm = document.getElementById("fp");
if (frm) frm.submit();
}
//-->1
2We've included the id attribute for the <form> and so we can use: getElementById DOM method which is better than using the document.elementname approach as this searches through all the DOM collections. With multiple FORMs on the page (in my experience) the latter didn't always return the object, whereas the former does. Anyway, hope this helps Cheers, Andy
-
uhm, I tried the exact code you described and it worked for me (in IE that is). Are you using a different browser? As reference though, this is a more programatically correct approach:
<!--
function onchangeOptions()
{
var frm = document.getElementById("fp");
if (frm) frm.submit();
}
//-->1
2We've included the id attribute for the <form> and so we can use: getElementById DOM method which is better than using the document.elementname approach as this searches through all the DOM collections. With multiple FORMs on the page (in my experience) the latter didn't always return the object, whereas the former does. Anyway, hope this helps Cheers, Andy
-
uhm, I tried the exact code you described and it worked for me (in IE that is). Are you using a different browser? As reference though, this is a more programatically correct approach:
<!--
function onchangeOptions()
{
var frm = document.getElementById("fp");
if (frm) frm.submit();
}
//-->1
2We've included the id attribute for the <form> and so we can use: getElementById DOM method which is better than using the document.elementname approach as this searches through all the DOM collections. With multiple FORMs on the page (in my experience) the latter didn't always return the object, whereas the former does. Anyway, hope this helps Cheers, Andy
Never ever submit a form
onchange
of a select! Reasons:- the user is not able to select options with the keyboard
- when the user uses the mouse wheel and the
select
has focus the form is again submitted by accident - the form will not be submitted if the user has JS disabled
Having that said here's another programatically correct approach:
<script type="text/javascript">
function doSubmit(frm) {
frm.submit();
}
</script>
...
<select onchange="doSubmit(this.form)">