Passing javascript variable from modal to php on the same page -


i stucking problem day.i want perform edit operation on script.my main page called customer-grid-screen.php code comes follows

<?php include("header.inc.php"); include("left.inc.php"); include('config.php');?>  <div id="page-content-wrapper">   <?php include("pagetitile.inc.php"); ?>   <div id="page-content">   <div class="clearfix mrg10b"><a href="javascript:;"   class="btn large bg-green float-right modal-customeradd" title=""><span class="button-content">add</span></a></div> <div class="example-box">     <div class="example-code">          <table class="table table-condensed">             <thead>                 <tr>                     <th>name</th>                     <th>details</th>                     <th>domain</th>                     <th>vertical</th>                     <th>taxanomy</th>                     <th>actions</th>                 </tr>             </thead>             <tbody>  <?php $result = mysql_query("select * customer_mast order customer_id") or trigger_error(mysql_error());  while($row = mysql_fetch_array($result)){  if($row<1) {     echo "</tr>";     echo "<tr>";     echo "<td colspan='6' class='text-center pad25a'>no record</td>";     echo "</tr>"; } else { foreach($row $key => $value){     $row[$key] = stripslashes($value);   }      echo "<tr>";       echo "<td><a href='customer-screen.php'>" . nl2br( $row['customer_name']) . "</td>";      if(!empty($row['customer_details'])){     echo "<td><a href='customer-screen.php'>". nl2br( $row['customer_details']) . "</td>";         }     else{        echo "<td><a href='customer-screen.php'>-</td>";     }     if(!empty( $row['domain']))     {     echo "<td><a href='customer-screen.php'>". nl2br( $row['domain']) . "</td>";}     else{        echo "<td><a href='customer-screen.php'>-</td>";     }     if(!empty($row['vertical'])){     echo "<td><a href='customer-screen.php'>". nl2br( $row['vertical']) . "</td>";}     else{         echo "<td><a href='customer-screen.php'>-</td>";     }     if(!empty($row['taxanomy'])){        echo "<td><a href='customer-screen.php'>". nl2br( $row['taxanomy']) . "</td>";     }     else     { echo "<td><a href='customer-screen.php'>-</td>";}           echo $row['customer_id'];       echo "<td>      <a href='javascript:?id={$row['customer_id']}'    data-id={$row['customer_id']} class='btn small bg-blue-alt tooltip-button modal-customeredit' data-placement='top' title='edit'><i class='glyph-icon icon-edit' ></i>      </a>     <a href='customer_delete.php?id={$row['customer_id']}'  class='btn small bg-red tooltip-button confirm' data-placement='top' title='remove'><i class='glyph-icon icon-remove'></i>    </a>    </td>";}}    ?>             </tbody>         </table>       </div>  </div>    </div><!-- #page-content -->     </div>             </div> <?php include("footer.inc.php"); ?> 

i have perform edit operation through modal pop up.i implemented code follows.

footer.inc.php ------------       <!-- project edit  see this-->     <div class="hide" id="modal-projedit" title="edit project info">     <div class="pad10a">     <h3>edit project info</h3>     <p class="font-gray-dark"> fides admin uses colors & styles both default theme color schemes , included core color helpers. </p>     <div class="divider mrg25b"></div>     <form id="project-edit" action="" class="col-md-12 center-margin" method="">     <div class="form-row">     <div class="form-label col-md-3">     <label for="name">       project name:       <span class="required">*</span>       </label>     </div>     <div class="form-input col-md-9">     <input id="name" name="name" placeholder="name" data-required="true" class="parsley-validated" type="text">     </div>     </div>     <div class="divider"></div>     <div class="form-row">     <div class="form-input col-md-8 col-md-offset-3">     <a href="javascript:;" class="btn medium primary-bg radius-all-4" id="project-edit-valid" onclick="javascript:$('#project-edit').parsley( 'validate' );" title="validate!">       <span class="button-content">         update         </span>       </a>     </div>     </div>     </form>     </div>     </div> //modal window script:  $( ".modal-customeredit" ).click(function() {          var mygroupid = $(this).data('id');           alert( mygroupid); //i can able alert paricular row id want edit dont know pass through php.      $( "#modal-customeredit" ).dialog({      modal: true,      minwidth: 700,      minheight: 200,      dialogclass: "modal-dialog",      show: "fadein"    });    $('.ui-widget-overlay').addclass('bg-black opacity-60');  });           //same page php file  <?php    $id=???; (get id not working)       $sql="select * `customer_mast` customer_id='$id'";    $result=mysql_query($sql);    if($result==false)       {       die(mysql_error());       }       else{       $row  = mysql_fetch_array($result);}        if (isset($_post['submit'])){ foreach($_post $key => $value) { $_post[$key] = mysql_real_escape_string($value); }  $sql = "update `customer_mast` set   `customer_name` =  '{$_post['customer_name']}' ,  `customer_details` =  '{$_post['customer_details']}',`domain` =  '{$_post['domain']}' ,`vertical` =  '{$_post['vertical']}' ,`taxanomy` =  '{$_post['taxanomy']}'   `customer_id` = '$id' ";  mysql_query($sql) or die(mysql_error());  echo (mysql_affected_rows()) ? "edited row.<br />" : "nothing changed. <br />";   header("location:customer-grid.php");}   ?> 

can please explain me how can pass id value php script on same page , peform edit operation.i can explain more if have doubts,i have gone through many things to make correct.nothing helped me.please give suggestion.

you should see how ajax working pass value php.

$( "#modal-customeredit" ).dialog({      modal: true,      minwidth: 700,      minheight: 200,      dialogclass: "modal-dialog",      show: "fadein"      buttons: {          edit: function() {            // sample ajax request ( see documentation)            $.ajax({                type: "post",                url: "request.php",                data: { id: mygroupid }, // data retrieve on server-side ($_post['id'])                datatype : 'html|json|...' // expected data returned            })            .success(function( msg ) {                alert( "data saved: " + msg );            });          },          cancel: function() {            $( ).dialog( "close" );          }     }     // stop event when form submit     return false; }); 

you have element yourself. 1 more advice, try separate files. instance execute treatment in file request.php.

edit :

sample request.php (i return json).

<?php    header('content-type: application/json'); // tell app want return json    $id= $_post['id']; // correspond retrieved data in ajax function     // ... sql request , other treatment     // result return    echo json_encode($result); ?> 

the data send ajax function in .success( data ).


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -