T
teddysnips
A newbie writes:
Is there any reason to choose one over the other of the following two
ways to write a Javascript function? The function is called when a
drop-down list is changed, and navigates to a different page depending
on the value chosen:
<script language="JavaScript">
<!--
// Version 1.0
function MoveToPage(el)
{//v1.0
if(el.options[el.selectedIndex].text=='value 1')
{
document.getElementById('form_eng').action =
'report1.asp';
}
else if(el.options[el.selectedIndex].text=='value 2')
{
document.getElementById('form_eng').action =
'report2.asp';
}
else if(el.options[el.selectedIndex].text=='value 3')
{
document.getElementById('form_eng').action =
'report3.asp';
}
document.getElementById('form_eng').submit();
}
-->
</script>
================
<script language="JavaScript">
<!--
//Version 1.1
function MoveToPage(el)
{//v1.1
var form;
form = document.getElementById('form_eng')
var
report=el.options[el.selectedIndex].text;
if(report=='value 1')
{
form.action = 'report1.asp';
}
else if(report=='value 2')
{
form.action = 'report2.asp';
}
else if(report=='value 3')
{
form.action = 'report3.asp';
}
form.submit();
}
-->
</script>
Is there any reason to choose one over the other of the following two
ways to write a Javascript function? The function is called when a
drop-down list is changed, and navigates to a different page depending
on the value chosen:
<script language="JavaScript">
<!--
// Version 1.0
function MoveToPage(el)
{//v1.0
if(el.options[el.selectedIndex].text=='value 1')
{
document.getElementById('form_eng').action =
'report1.asp';
}
else if(el.options[el.selectedIndex].text=='value 2')
{
document.getElementById('form_eng').action =
'report2.asp';
}
else if(el.options[el.selectedIndex].text=='value 3')
{
document.getElementById('form_eng').action =
'report3.asp';
}
document.getElementById('form_eng').submit();
}
-->
</script>
================
<script language="JavaScript">
<!--
//Version 1.1
function MoveToPage(el)
{//v1.1
var form;
form = document.getElementById('form_eng')
var
report=el.options[el.selectedIndex].text;
if(report=='value 1')
{
form.action = 'report1.asp';
}
else if(report=='value 2')
{
form.action = 'report2.asp';
}
else if(report=='value 3')
{
form.action = 'report3.asp';
}
form.submit();
}
-->
</script>