JavaScript Conditional
-
Hi, this is my post! :S
function GoPage(accion)
{
if(accion == "G")
window.location.href = 'resultadointerfaz.asp?vyear='+ document.getElementById('Select2').value+'&vmes='+document.getElementById('Select1').value+'&tipo='+document.getElementById('tipo').value+'&consultar=G';
else
window.location.href = 'resultadointerfaz.asp?vyear='+ document.getElementById('Select2').value+'&vmes='+document.getElementById('Select1').value+'&tipo='+document.getElementById('tipo').value+'&consultar=C';
}What do you think. I think that the else is not necesary! bye!
-
Hi, this is my post! :S
function GoPage(accion)
{
if(accion == "G")
window.location.href = 'resultadointerfaz.asp?vyear='+ document.getElementById('Select2').value+'&vmes='+document.getElementById('Select1').value+'&tipo='+document.getElementById('tipo').value+'&consultar=G';
else
window.location.href = 'resultadointerfaz.asp?vyear='+ document.getElementById('Select2').value+'&vmes='+document.getElementById('Select1').value+'&tipo='+document.getElementById('tipo').value+'&consultar=C';
}What do you think. I think that the else is not necesary! bye!
there is a 1-letter difference near the end! :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use < PRE > tags for code snippets, it preserves indentation, and improves readability.
modified on Wednesday, June 23, 2010 7:41 PM
-
there is a 1-letter difference near the end! :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use < PRE > tags for code snippets, it preserves indentation, and improves readability.
modified on Wednesday, June 23, 2010 7:41 PM
-
there is a 1-letter difference near the end! :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use < PRE > tags for code snippets, it preserves indentation, and improves readability.
modified on Wednesday, June 23, 2010 7:41 PM
yes there is =D but the whole function could be written better, with regard to DRY
-
Hi, this is my post! :S
function GoPage(accion)
{
if(accion == "G")
window.location.href = 'resultadointerfaz.asp?vyear='+ document.getElementById('Select2').value+'&vmes='+document.getElementById('Select1').value+'&tipo='+document.getElementById('tipo').value+'&consultar=G';
else
window.location.href = 'resultadointerfaz.asp?vyear='+ document.getElementById('Select2').value+'&vmes='+document.getElementById('Select1').value+'&tipo='+document.getElementById('tipo').value+'&consultar=C';
}What do you think. I think that the else is not necesary! bye!
-
Hi, this is my post! :S
function GoPage(accion)
{
if(accion == "G")
window.location.href = 'resultadointerfaz.asp?vyear='+ document.getElementById('Select2').value+'&vmes='+document.getElementById('Select1').value+'&tipo='+document.getElementById('tipo').value+'&consultar=G';
else
window.location.href = 'resultadointerfaz.asp?vyear='+ document.getElementById('Select2').value+'&vmes='+document.getElementById('Select1').value+'&tipo='+document.getElementById('tipo').value+'&consultar=C';
}What do you think. I think that the else is not necesary! bye!
-
Hi, this is my post! :S
function GoPage(accion)
{
if(accion == "G")
window.location.href = 'resultadointerfaz.asp?vyear='+ document.getElementById('Select2').value+'&vmes='+document.getElementById('Select1').value+'&tipo='+document.getElementById('tipo').value+'&consultar=G';
else
window.location.href = 'resultadointerfaz.asp?vyear='+ document.getElementById('Select2').value+'&vmes='+document.getElementById('Select1').value+'&tipo='+document.getElementById('tipo').value+'&consultar=C';
}What do you think. I think that the else is not necesary! bye!
We love copy and paste.
-
Hi, this is my post! :S
function GoPage(accion)
{
if(accion == "G")
window.location.href = 'resultadointerfaz.asp?vyear='+ document.getElementById('Select2').value+'&vmes='+document.getElementById('Select1').value+'&tipo='+document.getElementById('tipo').value+'&consultar=G';
else
window.location.href = 'resultadointerfaz.asp?vyear='+ document.getElementById('Select2').value+'&vmes='+document.getElementById('Select1').value+'&tipo='+document.getElementById('tipo').value+'&consultar=C';
}What do you think. I think that the else is not necesary! bye!
I think:
function GoPage(accion) { if (accion == "G") { consultar_val = G; } else { consultar_val = C; } window.location.href = 'resultadointerfaz.asp?vyear='+document.getElementById('Select2').value+'&vmes='+document.getElementById('Select1').value+'&tipo='+document.getElementById('tipo').value+'&consultar='+consultar_val; }
<Pretentious> Raid tha manyuhl. :E <Pretentious> Aw raid eh own mah meaxbile. :E
-
I think:
function GoPage(accion) { if (accion == "G") { consultar_val = G; } else { consultar_val = C; } window.location.href = 'resultadointerfaz.asp?vyear='+document.getElementById('Select2').value+'&vmes='+document.getElementById('Select1').value+'&tipo='+document.getElementById('tipo').value+'&consultar='+consultar_val; }
<Pretentious> Raid tha manyuhl. :E <Pretentious> Aw raid eh own mah meaxbile. :E
-
<select id="Select4"><option>Bad Idea></option></select> <select id="Select2"><option>Bad idea></option></select> <select id="Select7"><option>bad Idea></option></select> <select id="Select5"><option>bad idea></option></select> <select id="Select1"><option>BadIdea></option></select> <select id="Select6"><option>badIdea></option></select> <select id="Select3"><option>Bad_Idea></option></select> <select id="Select8"><option>bad_idea></option></select>
<Pretentious> Raid tha manyuhl. :E <Pretentious> Aw raid eh own mah meaxbile. :E
-
Since setting of
href
does not necessary stop the scripts and jump to new address, I think thatelse
is required. But the code can be probably replaced with a single line like this:window.location.href = "...&consultar=" + accion;
If action is, for example, 'X', your function works differently to the original
-
I think:
function GoPage(accion) { if (accion == "G") { consultar_val = G; } else { consultar_val = C; } window.location.href = 'resultadointerfaz.asp?vyear='+document.getElementById('Select2').value+'&vmes='+document.getElementById('Select1').value+'&tipo='+document.getElementById('tipo').value+'&consultar='+consultar_val; }
<Pretentious> Raid tha manyuhl. :E <Pretentious> Aw raid eh own mah meaxbile. :E
Or, simpler:
function GoPage(accion)
{
window.location.href =
'resultadointerfaz.asp?vyear=' +
document.getElementById('Select2').value +
'&vmes=' +
document.getElementById('Select1').value +
'&tipo=' +
document.getElementById('tipo').value +
'&consultar=' +
(accion == 'G' ? 'G' : 'C');
} -
Or, simpler:
function GoPage(accion)
{
window.location.href =
'resultadointerfaz.asp?vyear=' +
document.getElementById('Select2').value +
'&vmes=' +
document.getElementById('Select1').value +
'&tipo=' +
document.getElementById('tipo').value +
'&consultar=' +
(accion == 'G' ? 'G' : 'C');
}I wanted to use the ternary operator there, too; then I thought of the future case of adding a third "accion" and decided to leave an obvious ability to add an "else if" condition at the top.
<Pretentious> Raid tha manyuhl. :E <Pretentious> Aw raid eh own mah meaxbile. :E