jimgwhit said:
thank you I know it but i want to know laravel 5 can handle it ? or i must write it?
Have you looked for a jquery solution, laravel is a php framework. But jquery works well with laravel. or have a drop down without ajax.
http://stackoverflow.com/questions/10870667/populate-select-box-from-database-using-jquery
don't mess with, rather learn how to use jquery ajax. You'll be happier in the end.
jimgwhit said:
don't mess with, rather learn how to use jquery ajax. You'll be happier in the end.
please tell me a more clear answer,i couldn't what do you say.
for another example when i login i don't want to refresh all page i want to refresh top menu
If you are new to this, practice first, take a while to learn jquery. Short of that try phprunner, it will generate code for you. Laravel is a php framework where you should already be well versed in php, pdo, HTML, and jquery or JavaScript.
I haven't used a dropdown, but I use a popup lookup table, so here is a example: In my edit page I "lookup" the owner:
edit page partial
<tr>
<td class="aright">ownerid:</td>
<td>
<input type="text" name="ownerid" id="ownerid" value="<?php echo $data->ownerid;?>">
<?php
echo '<a href="JavaScript:void(0);" onclick="Lookup()">Click Me</a>';
//use \helpers\session as Session;
?>
</td>
</tr>
Javascript to open the popup window to have the table to select owner from:
code to open popup
function Lookup() {
var iMyWidth;
var iMyHeight;
//half the screen width minus half the new window width (plus 5 pixel borders).
iMyWidth = (window.screen.width / 2) - (250 + 10);
//half the screen height minus half the new window height (plus title and status bars).
iMyHeight = (window.screen.height / 2) - (250 + 50);
//Open the window.
//var map = window.open("/mvc/owner", "map", "status=no,height=500,width=500,resizable=yes,left=" + iMyWidth + ",top=" + iMyHeight + ",screenX=" + iMyWidth + ",screenY=" + iMyHeight + ",toolbar=no,menubar=no,scrollbars=no,location=no,directories=no");
var map = window.open("findowner", "map", "status=no,height=500,width=500,resizable=yes,left=" + iMyWidth + ",top=" + iMyHeight + ",screenX=" + iMyWidth + ",screenY=" + iMyHeight + ",toolbar=no,menubar=no,scrollbars=no,location=no,directories=no");
}
controller code for find owner
public function findowner()
{
//include 'mypager2.php';
include 'mypager2.php';
if(isset($_REQUEST['t1']))
{
$t1 = $_REQUEST['t1'];
}
else
{
$t1 = "";
}
$ownersearch = $t1;
$ownersearch = $ownersearch . "%";
$krows = DB::table('powners')->where('oname', 'like', $ownersearch)->count();
$pages = new Mypager2('5','page');
$pages->set_total($krows);
//echo $krows;
//echo $pages->get_perpage();
$data['owners'] = DB::table('powners')
->where('oname', 'like', $ownersearch)
->orderBy('oname', 'asc')
->skip($pages->get_limit2())->take($pages->get_perpage())->get();
$data['page_links'] = $pages->page_links('?','&t1='.$t1);
//$mpage = $pages->page_links('?','&t1='.$t1);
//echo $mpage;
//echo $data['page_links'];
//$owners = DB::select('select * from powners'); //good works
//print_r($data['page_links']);
return View::make('owner/findowner')->with('data',$data['owners'])->with('data2',$data['page_links']);
}
the findowner and jquery code to get the owner
<html>
<head>
<script type="text/javascript" src="include/jquery.js"></script>
<script type="text/javascript" src="include/myjq.js"></script>
<link rel="stylesheet" href="include/style2.css" type="text/css">
</head>
<body>
<?php
echo "<br>";
//echo "<div id=tblcont2>";
echo
'<table id="myTable" border="1" align="left" cellpadding="6" cellspacing="0">'.
'<thead style="background-color:lightblue">'.
'<tr>'.
'<th>ownerid</th>'.
'<th>oname</th>'.
'<th>ostreet</th>'.
'<th>odate</th>'.
'<th>ocheck</th>'.
'</tr>'.
'</thead>';
foreach ($data as $owner){
//echo $owner['oname'];//works with ORM also
//echo $owner->oname; //use with database and querybuilder and ORM
echo "<tr>";
echo "<td>"."<a href=\"\" >".$owner->ownerid."</a>"."</td>";
echo "<td>"."<a>".$owner->oname."</a>"."</td>";
echo "<td>"."<a>".$owner->ostreet."</a>"."</td>";
echo "<td>"."<a>".$owner->odate."</a>"."</td>";
echo "<td>"."<a>".$owner->ocheck."</a>"."</td>";
echo "</tr>";
}
echo "</table>";
echo "<br>";
echo '<table style="width:70%;">';
echo '<tr>';
echo '<td>' . $data2 . '</td>';
echo '</tr></table>';
//echo "</div>";
//echo $data2;
//echo "<p>{$data2}</p>";
//echo 'hi';
?>
</body>
<script>
$(function() {
$("#myTable td:nth-child(1)").click(function(event)
{
event.preventDefault();
var $td= $(this).closest('tr').children('td');
var currentCellText = $td.eq(0).text();
var CellText = $td.eq(1).text();
alert("hello");
$.ajax({
url:'<?php echo "getowner";?>',
type: 'GET',
data: 'id='+currentCellText,
dataType: 'json',
success: function(data) {
//window.opener.$('input#petowner').val(data.petowner);
alert(data.oname);
window.opener.$('#ownerid').val(data.ownerid);
window.opener.$('#petowner').val(data.oname);
window.opener.$('#ostreet').val(data.ostreet);
window.opener.$('#odate').val(data.oodate);
if(data.ocheck == '1')
{
alert("yesyes");
window.opener.$('#ocheck').attr('checked', true);
}
else
{
alert("nono");
window.opener.$('#ocheck').attr('checked', false);
}
self.close();
}
});
});// JavaScript Document
}); ///end function
</script>
</html>
controller for get owner, this has no view, returned directly from controller, and fills the 3 fields.
public function getowner(){
$ownerid = $_GET['id'];
$data['owners']=Powner::find($ownerid);
return Response::json($data['owners']);
}
I know php , html and A little jquery and javascript but I want to know laravel 5 has those featcures that I said?if yes how can use it?
Read my example, you have to use jquery etc, that's how to implement. Laravel isn't going to write the code for you. You have to include jquery, and program the code yourself. Read my example above, I showed you I I rolled up my sleeves and actually implemented some jquery ajax. My example is in laravel 4, I haven;t done this in L5 yet.
Again laravel is a php framework, you have to include jquery just like you would in php.
really thank you very much ;) you are very very good friend :) really thank you
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community