php - Show alert with the content of a Database selection -
i new javascript related it.
i have set of dynamic rows , corresponding columns rows. in 1 column have button. when click on it, displays results of select
query in page based on posted competence_id.
the query works fine , correct results when click on button. however, now, display message in an alert when button clicked , stay on same page rather opening new tab..
here relevant html code shows table use:
echo "<table border='1' id='mycompstable' class='sortablee' cellpadding='0' cellspacing='0'>"; echo "<tr><th>id</th><th>competence group</th><th>competence class</th><th>competence description</th><th>own evaluation</th><th>manager's evaluation last year</th><th>target levels</th><th>gap</th><th>action</th><th class='unsortable'>action ready target </th></tr>"; foreach($descs $compi){ echo "<tr>"; echo "<td>".$compi['competence_id']."</td>"; echo "<td><p style='text-align: center;'>".$compi['competence_group']."</p></td>"; if(isset($compi['competence_class'])){echo "<td>".$compi['competence_class']."</td>";}else echo "<td><p style='text-align: center;'>-</p></td>"; echo "<td>".$compi['competence_description']."</td>"; echo "<td class='evaluation'>"; echo "<select class='ownlevelselect' id='ownlevelselect-.".$compi['competence_id']."' name='level-".$compi['competence_id']."' >"; if (isset($compi['ownlevel']) && $compi['ownlevel']!= '' && !empty($compi['ownlevel']) && $compi['ownlevel']!= 0) { echo "<option selected value='".$compi['ownlevel']."' selected='selected'>".$compi['ownlevel']."</option>"; } echo "<option value='' >--</option>"; echo "<option value='1'>1</option><option value='2'>2</option><option value='3'>3</option><option value='4'>4</option><option value='5'>5</option>"; echo "</select>"; echo $compi['ownlevel']; echo '<a test="'.$compi['competence_id'].'" onclick="showlevels('.$compi['competence_id'].');" target="_blank" href="'.index.'?categ='.$_get['categ'].'&action='.$_get['action'].'&subaction=viewlevels'.'&levels='.$compi['competence_id'].'">'; echo '<img class="linkki" src="'.kuvat.'paivita.gif" alt="'._("tiedot").'" title="'._("click view description of each level?").'"/></a>'; echo "</td>";
here code retrieve data:
function fetchlevels($competence_id){ $this->query="select * levels comp_id=".$_request['levels']; $tulos=$this->suoritakysely(); return $tulos; }
and here page want show in message:
$levels=$this->levels; $comp=$this->compdesc; echo "levels explanation competence:".$comp['competence_description']."<br>"; echo "level 1 = ".$levels[0]['lvl1']; echo "<br>"."level 2 = ".$levels[0]['lvl2']; echo "<br>"."level 3 = ".$levels[0]['lvl3']; echo "<br>"."level 4 = ".$levels[0]['lvl4']; echo "<br>"."level 5 = ".$levels[0]['lvl5']; echo "<br><br>"; echo '<input type="button" value="close" window onclick="window.close();">'; ?>
any kind of appreciated
here ajax simulation in jsfiddle http://jsfiddle.net/ncubica/umxjb/
html
<i style='display:none' id="loadingpopup">loading</i> <table> <tr> <td data-id="td1"> row 1</td> </tr> <tr> <td data-id="td2"> row 2</td> </tr> <tr> <td data-id="td3"> row 3</td> </tr> </table>
javascript
$("table").on("click", function(event){ var $target = $(event.target); if($target.is("td")){ var id = $target.attr("data-id"); makeajax(id); } }); //simulating ajax function makeajax(id){ //you have use ajax retrieve json format //i simulate ajax $("#loadingpopup").show(); var _json = { id : id, value : "some value", description : "some description"}; settimeout(function(){response(_json)}, 1000); } function response(_json){ $("#loadingpopup").hide(); alert(_json.id + " - " + _json.value); }
css
table{font-family:arial; font-size:12px; width:100%} table tr td{border-bottom:1px solid #ccc; padding:10px;}