call java script function

Discussion in 'PHP' started by srini_r85, Jun 1, 2010.

  1. #1
    hi,

    i need to call the java script function from php.here my code

    $strQuery = "select name from markers LIMIT 0 , 10";

    $rsrcResult = mysql_query($strQuery);

    echo "<select name='logdropdown' >";

    while($arrayRow = mysql_fetch_assoc($rsrcResult)) {

    $type= $arrayRow["name"];

    $id= $arrayRow["$id"];


    echo "<option value=''>$type<option/>";

    }

    echo "</select>\n\n";

    i need to call function searchLocation() and selected option pass as i/p to seachlocation function.

    my java script code


    function searchLocations() {
    var address = document.getElementById('addressInput').value;
    geocoder.getLatLng(address, function(latlng) {
    if (!latlng) {
    alert(address + ' not found');
    } else {
    searchLocationsNear(latlng);
    }
    });
    }


    how it is possible.is any one help me do that.


    thanks
     
    srini_r85, Jun 1, 2010 IP
  2. tolra

    tolra Active Member

    Messages:
    515
    Likes Received:
    36
    Best Answers:
    1
    Trophy Points:
    80
    #2
    Just stick a call to the functions you want at the end of the page output then as the browser renders the page they will run, or use the onload event.
     
    tolra, Jun 1, 2010 IP
  3. wigwambam

    wigwambam Peon

    Messages:
    40
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    echo "<script language=javascript>searchLocation()</script>";
     
    wigwambam, Jun 1, 2010 IP
  4. srini_r85

    srini_r85 Peon

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    how i implement this code.will you explain more detail.

    thanks
     
    srini_r85, Jun 1, 2010 IP
  5. qrpike

    qrpike Peon

    Messages:
    26
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    just call in php:

    <?php echo '<script> function_name(); </script>'; ?>

    PHP is serverside and is compiled before any HTML is loaded, therefor you must make php echo this so when the page is loaded in the browser it calls the JS function.

    - Scripteen.com
     
    qrpike, Jun 6, 2010 IP
  6. qrpike

    qrpike Peon

    Messages:
    26
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Or you can actually just call it at the bottom of the page like wigwambam said.

    - scripteen.com
     
    qrpike, Jun 6, 2010 IP