By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,660 Members | 1,945 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,660 IT Pros & Developers. It's quick & easy.

JavaScript not working in IE and Safari, works in Firefox fine.

P: n/a
I have a simple function that does submit for me:

<script language="javascript" type="text/javascript">
function sort()
{
//selected item value from the drop down list

var dud=window.document.statusForm.sortByStaff.value;
window.document.statusForm.action="status.cfm?sort By="+dud;
window.document.statusForm.method="post";
window.document.statusForm.submit();
}
</script>

I have several drop down boxes (<select> element) in which i set
onclick="sort()". Works perfectly in Firefox, and doesn't work in IE
and Safari. Also this same function works fine in all 3 if appended to
a button instead of select element. What am I doing wrong?

Feb 17 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
VK

dp******@gmail.com wrote:
I have a simple function that does submit for me:

<script language="javascript" type="text/javascript">
function sort()
{
//selected item value from the drop down list

var dud=window.document.statusForm.sortByStaff.value;
window.document.statusForm.action="status.cfm?sort By="+dud;
window.document.statusForm.method="post";
window.document.statusForm.submit();
}
</script>

I have several drop down boxes (<select> element) in which i set
onclick="sort()". Works perfectly in Firefox, and doesn't work in IE
and Safari. Also this same function works fine in all 3 if appended to
a button instead of select element. What am I doing wrong?


....
<script type="text/javascript">
function sortBy(category) {

with(category.form) {
action="status.cfm?sortBy="+category;

// Are you switching from GET to POST ?
// Otherwise it is more reasonnable to indicate
// the form method once in the form itself
method="POST";

submit();
}
}
</script>
</head>
<body>
....
<form name="categoryForm" method="post" action="">
....
<select name="staff" onchange="sortBy(this[this.selectedIndex].value)">
....

Feb 17 '06 #2

P: n/a
I have simplified the function based on your advice, but still was only
able to obtain result in Firefox with onclick set instead of onchange.
When I use onchage nothing works anywhere.

function sortStaff(action)
{
window.document.statusForm.action="status.cfm?sort By="+action;
window.document.statusForm.submit();

}

<select name="staff"
onchange="sortStaff(this.options[this.selectedIndex].value)">

I am not switching from POST to GET so I just moved method into form
declaration from javascript.

Feb 17 '06 #3

P: n/a
VK

dp******@gmail.com wrote:
I have simplified the function based on your advice
But you still prefer to use "lazy syntacs" instead of the proper one:
document.forms[...].elements[...]
OK, it's your code - but don't say you weren't alerted.

but still was only
able to obtain result in Firefox with onclick set instead of onchange.
"onclick" is not promised to work with select elements. Select elements
do support guaranteed onfocus - onchange - onblur handlers.
When I use onchage nothing works anywhere.


Which means that you have some other error somewhere. Compare this
testcase with your page to find out where:

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<script>
function sortStaff(action)
{
document.statusForm.action="status.cfm?sortBy="+ac tion;
alert(document.statusForm.action);
}
</script>

</head>

<body bgcolor="#FFFFFF">

<form method="post" action="" name="statusForm">
<select name="select1"
onchange="sortStaff(this[this.selectedIndex].value)">
<option value="1" selected>1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
</form>
</body>
</html>

Feb 17 '06 #4

P: n/a
He he

Ok, i found all the dumb things I did. onchange doesn't work when
attached to options :). Moved to element declaration and everything
works fine.
IE doesn't support onclick and i guess safari doesn't either.

Feb 17 '06 #5

P: n/a
dp******@gmail.com wrote:
Ok, i found all the dumb things I did. onchange doesn't work when
attached to options :). Moved to element declaration and everything
works fine.


JFYI: /That/ is _not_ called an (element) declaration:

<select name="staff" onchange="...">

It is called the start tag of the `select' element.

This is called an element declaration:

<!ELEMENT SELECT - - (OPTGROUP|OPTION)+ -- option selector -->

It declares the `select' element (in the Document Type Definition)
so that you can use it in your markup later.
PointedEars
Feb 17 '06 #6

P: n/a
Thomas 'PointedEars' Lahn said the following on 2/17/2006 3:56 PM:
dp******@gmail.com wrote:
Ok, i found all the dumb things I did. onchange doesn't work when
attached to options :). Moved to element declaration and everything
works fine.


JFYI: /That/ is _not_ called an (element) declaration:

<select name="staff" onchange="...">

It is called the start tag of the `select' element.

This is called an element declaration:

<!ELEMENT SELECT - - (OPTGROUP|OPTION)+ -- option selector -->

It declares the `select' element (in the Document Type Definition)
so that you can use it in your markup later.


To the OP: Ignore Thomas. He thinks he knows more than anybody else but
he seldom does.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Feb 18 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.