PDA

View Full Version : I used onchange [drop down "location menues") but function do NOT called ONCHANGE the



leonidassavvides
02-20-2009, 12:08 PM
At http://www.poliscarhire.com/test/test-car-menu-page.php
I used onchange [drop down "location menues") but function do NOT called ONCHANGE the drop down where the error ?

head:


<script language="javascript" type="text/javascript">
<!--
function showRow1()
{
alert("called showRow1()");
alert(document.getElementById('pickUpLocation').selectedIndex);
if (document.getElementById('pickUpLocation').selectedIndex==2 or document.getElementById('pickUpLocation').selectedIndex==3) { // "Other Accomodation" "Hotel in Cyprus" dropOffLocation pickUpLocation
document.getElementById('accomodation1').style.display = '';
} else {
document.getElementById('accomodation1').style.display = 'none';
}
}
document.getElementById('accomodation1').style.display = 'none';
document.getElementById('accomodation2').style.display = 'none';

function showRow2()
{
if (document.getElementById('dropOffLocation').value=="Other Accomodation" or document.getElementById('dropOffLocation').value=="Hotel in Cyprus") { // dropOffLocation pickUpLocation
document.getElementById('accomodation2').style.display = '';
} else {
document.getElementById('accomodation2').style.display = 'none';
}
}
//-->
</script>


<select id="select2" name="pickUpLocation" tabindex="50" style="font-size: 11px" onchange="showRow1();" >
<option>Paphos Airport</option>
<option>Larnaca Airport</option>
<option>Hotel in Cyprus</option>
<option>Other Accomodation</option>
<option selected="selected">Polis Office</option>
<option>Latchi Office</option>
</select>


<script language="JavaScript" type="text/javascript">
document.getElementById('accomodation1').style.display = 'none';
document.getElementById('accomodation2').style.display = 'none';
</script>

magicyte
02-20-2009, 12:59 PM
There shouldn't be a drop-down error, but I do see [an] error[s]. I'm pretty sure that "or" isn't allowed in javascript, since I've been coding in it for a while, but only allowed in PHP. Try "||" instead:


function showRow1()
{
alert("called showRow1()");
alert(document.getElementById('pickUpLocation').selectedIndex);
if (document.getElementById('pickUpLocation').selectedIndex==2 || document.getElementById('pickUpLocation').selectedIndex==3) { // "Other Accomodation" "Hotel in Cyprus" dropOffLocation pickUpLocation
document.getElementById('accomodation1').style.display = '';
} else {
document.getElementById('accomodation1').style.display = 'none';
}
}
document.getElementById('accomodation1').style.display = 'none';
document.getElementById('accomodation2').style.display = 'none';

function showRow2()
{
if (document.getElementById('dropOffLocation').value=="Other Accomodation" || document.getElementById('dropOffLocation').value=="Hotel in Cyprus") { // dropOffLocation pickUpLocation
document.getElementById('accomodation2').style.display = '';
} else {
document.getElementById('accomodation2').style.display = 'none';
}
}

Nile
02-20-2009, 01:09 PM
Also, the <select> div doesn't have the id pickUpLocation...

magicyte
02-21-2009, 01:35 AM
I think you meant "dropOffLocation".

leonidassavvides
02-21-2009, 07:35 AM
Please note that problem is statement prior "if", do NOT get called

alert("called showRow1()");

hence function do not called at all ? well ?

magicyte
02-21-2009, 03:49 PM
Doubt this'll work, but try this. It may be the solution to your problem. You were using <!-- //--> which is OLD!!! Also, do not use the languages attribute. Here:


<script type="text/javascript">
function showRow1()
{
alert("called showRow1()");
alert(document.getElementById('pickUpLocation').selectedIndex);
if (document.getElementById('pickUpLocation').selectedIndex==2 or document.getElementById('pickUpLocation').selectedIndex==3) { // "Other Accomodation" "Hotel in Cyprus" dropOffLocation pickUpLocation
document.getElementById('accomodation1').style.display = '';
} else {
document.getElementById('accomodation1').style.display = 'none';
}
}
document.getElementById('accomodation1').style.display = 'none';
document.getElementById('accomodation2').style.display = 'none';

function showRow2()
{
if (document.getElementById('dropOffLocation').value=="Other Accomodation" or document.getElementById('dropOffLocation').value=="Hotel in Cyprus") { // dropOffLocation pickUpLocation
document.getElementById('accomodation2').style.display = '';
} else {
document.getElementById('accomodation2').style.display = 'none';
}
}
</script>

It may even depend on the browser YOU'RE using. What browser might you use?

leonidassavvides
02-22-2009, 01:09 AM
problem solved by changing "or" seems all script became inactive by this , thks