Results 1 to 7 of 7

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

  1. #1
    Join Date
    Oct 2004
    Posts
    425
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default I used onchange [drop down "location menues") but function do NOT called ONCHANGE the

    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:

    Code:
    <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>
    Code:
    <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>
    Code:
    <script language="JavaScript" type="text/javascript">
    document.getElementById('accomodation1').style.display = 'none';  
    document.getElementById('accomodation2').style.display = 'none';  
        </script>

  2. #2
    Join Date
    Jun 2008
    Posts
    589
    Thanks
    13
    Thanked 54 Times in 54 Posts
    Blog Entries
    1

    Default

    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:

    Code:
    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';  
    	}
    }

  3. #3
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Also, the <select> div doesn't have the id pickUpLocation...
    Jeremy | jfein.net

  4. #4
    Join Date
    Jun 2008
    Posts
    589
    Thanks
    13
    Thanked 54 Times in 54 Posts
    Blog Entries
    1

    Default

    I think you meant "dropOffLocation".

  5. #5
    Join Date
    Oct 2004
    Posts
    425
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default

    Please note that problem is statement prior "if", do NOT get called

    alert("called showRow1()");

    hence function do not called at all ? well ?

  6. #6
    Join Date
    Jun 2008
    Posts
    589
    Thanks
    13
    Thanked 54 Times in 54 Posts
    Blog Entries
    1

    Default

    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:

    Code:
    <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?

  7. #7
    Join Date
    Oct 2004
    Posts
    425
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default

    problem solved by changing "or" seems all script became inactive by this , thks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •