dcsimg
A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Send an updated php-variable to a javascript function

  1. #1
    Member
    Join Date
    Oct 2005
    Posts
    63

    Send an updated php-variable to a javascript function

    Is there a way to update php-variables that are sent to a javscript function with a onClick-event without updating the whole session?

    When you click the button I want to send a new query to the datebase and check the updated database value, where $status['kon'] is the database value I want to get.

    PHP Code:
    <td width="15%" align="right"><img src="images/arrow-r-icon.jpg" alt="" width="18" height="20" id="<?=$subdepartment[$a]['id']?>konsub_<?=$a?>" class="imgover" onClick="konavdh('<?=$subdepartment[$a]['id']?>kon','<?=$subdepartment[$a]['id']?>','<?=$status['kon']?>','<?=$subdepartment[$a]['kon']?>','<?=$menu[$j]['name']?>');"/></td>
    The js-function:
    Code:
    function konavdh(id,depid,type,subid,subname)
    {
     
    
     
     var konet=$('#'+id).val();
     
    
     
     if(kontyp[id]=='M/K')
     {
      konet='M'; 
     }
     if(kontyp[id]=='K')
     {
      konet='M/K'; 
     }
     
     if(kontyp[id]=='M')
     {
      konet='K'; 
     }
     
     }
     else {*/
     
      if(type=='')
     {
      konet='M'; 
     }
     
     
     if(type=='M/K')
     {
      konet='M'; 
     }
     if(type=='K')
     {
      konet='M/K'; 
     }
     
     if(type=='M')
     {
      konet='K'; 
     }
    
     
     
     $('#'+id).val(konet);
     
     $('#'+id+'value').html($('#'+id).val());
     autoSave(depid);
      $.modal.close();
        
     /*  });
      }
     });*/
     
    }
    The idea is to get a updated value of $status[0] (var type in javascript) everytime the onClick-event is triggered. The autoSave(depid) function updates the database with the variable "konet".

    One way could be to start a php-function at the same time as the onClick-event:

    PHP Code:
    function updateDb(depid)
     
    {

     
    $depart=$_POST['depid'];
     
    $sqlgen="select kon from chk_subdepartment where id='".$depid."'";
              
    $sqlgenupdate=mysql_query($sqlgen);
              
    $rowgen=mysql_fetch_row($sqlgenupdate);
              
              
    return 
    $status[0]=$rowgen[0];
     

    Unfortunately that don't work because php is executes on the server...

    Is there a way to send the updated database value to the javascript function?

  2. #2
    Registered User nunomira's Avatar
    Join Date
    May 2002
    Location
    portugal
    Posts
    7,003
    hi,

    PHP variables are executed on the server and can be sent to the browser (in the form of HTML or JavaScript, ...).

    If you want to update a JavaScript variable with some value that comes from the server, you'll need to make a new request to the server.
    Usually this results in a page refresh. As you don't want to refresh the page, you'll have to use Ajax to do it.

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center