Search the Community
Showing results for tags 'javascript'.
-
I am using Yii 2 framework and I have a search form with input fields and 2 submit buttons Search and Export. When the user clicks on Search button then index action should execute and when user clicks on Export button then export action should execute. Now even if user clicks on Export button export action is not executed. Below is the search form <?php use yii\helpers\Html; use yii\widgets\ActiveForm; use yii\helpers\ArrayHelper; use app\models\Asccenter; use app\models\Ascuser; ?> <?php $form = ActiveForm::begin([ 'method' => 'get', 'id'=>'form1' ]); ?> <?= $form->field($model, 'ASCId')->dropDownList()?> <?php //Input field 1?> <?= $form->field($model, 'UserId')?> <?php // Input field 2?> <?= $form->field($model, 'Year')?> <?php // Input field 3?> <div class="form-group"> <?php // Search button. When user clicks on Search button then index action should execute ?> <?= Html::submitButton('Search' ,['class' => 'btn btn-primary','id'=>'searchbutton','name'=>'search1','value'=>'search2']) ?> <?php //Reset button to clear the form inputs?> <?= Html::a('Reset',['index'], ['class' => 'btn btn-default']) ?> <?php // Export button. When user clicks on Export button, then export action should execute?> <?= Html::submitButton('Export', ['class' => 'btn btn-default','id'=>'exportbutton','name'>'search1','value'=>'export1']) ?> </div> <?php ActiveForm::end(); ?> Below is the Controller <?php namespace app\controllers; use Yii; use app\models\Ascteacherreport; use app\models\AscteacherreportSearch; use yii\helpers\ArrayHelper; class AscteacherreportController extends Controller { public function actionIndex() { // When user clicks on Search button then this action should execute $searchModel = new AscteacherreportSearch(); if (!Yii::$app->user->can('indexAll')) { $searchModel->UserId = Yii::$app->user->identity->getonlyid(); } $dataProvider = $searchModel->search(Yii::$app->request->queryParams); $query= Ascteacherreport::find(); $count=$query->count(); $pagination= new Pagination(['defaultPageSize' => 5, 'totalCount' => $count]); $training = $query->offset($pagination->offset)->limit($pagination->limit)->all(); return $this->render('index', [ 'searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'pagination' => $pagination, ]); } public function actionExport() { // When user clicks on Export button of the form then form parameters will be loaded and this action should execute. } }
-
I am using jui datepicker. I have a table which has columns StartYear and EndYear set to varchar data type. I need to store the Start Year in the format of Month Year for example Start Year : Jan 2023 End Year : Jan 2024 I have configured the jui date picker to show only Month and Year. Data is getting correctly saved in the table in create action, but on the update form the same data is not fetched correctly as shown in below image Below is the code _form.php <?php use yii\helpers\Html; use yii\bootstrap\ActiveForm; use yii\jui\DatePicker; use yii\helpers\ArrayHelper; ?> <style type="text/css"> .ui-datepicker-calendar { display: none; } </style> <script> $(document).ready(function() { $('.picker').datepicker({ changeMonth: true, changeYear: true, dateFormat: 'MM yy', onClose: function() { var iMonth = $("#ui-datepicker-div .ui-datepicker-month :selected").val(); var iYear = $("#ui-datepicker-div .ui-datepicker-year :selected").val(); $(this).datepicker('setDate', new Date(iYear, iMonth, 1)); }, }); }); </script> <?php $form = ActiveForm::begin();?> <?= $form->field($model, 'StartYear')->widget(DatePicker::classname(), [ //'language' => 'ru', 'options' => ['class' => 'form-control picker','readOnly'=>'readOnly'], 'clientOptions'=>['changeMonth'=>true, 'changeYear'=>true, 'dateFormat' => 'MM yy', 'readOnly'=>true] ]) ?> <?= $form->field($model, 'EndYear')->widget(DatePicker::classname(), [ //'language' => 'ru', 'options' => ['class' => 'form-control picker','readOnly'=>'readOnly'], 'clientOptions'=>['changeMonth'=>true, 'changeYear'=>true, 'dateFormat' => 'MM yy', 'readOnly'=>true] ]) ?> <?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> <?php ActiveForm::end(); ?>
-
I am retriving records from mysql database that has expiry time limit. The time in the database is saved in "minutes". So for one hour, it'll be "3600" minutes. That's all fine. Now what I am trying to do is create a countdown clock using Javascript/jquery and I have ran into a bit of a problem. 1. I am retriving multiple records from the database that all have a countdown timer. Currently, it's only taking the time value of the first record and using that for all the records. I would like to know how I can make it so that each record will have it's own countdown timer value? 2. Everytime I refresh a page, it will reset the timer. How can I fix this? Here's my code. <?php foreach($rows as $row) { $get_expiry_time = $row['expiry_time']; <div class="record"> <div class="timer"> </div> </div> } ?> <script> $(document).ready(function(){ var countDownTime = <?php echo $get_expiry_time; ?>; function countDownTimer() { var hours = parseInt( countDownTime / 3600 ) % 24; var minutes = parseInt( countDownTime / 60 ) % 60; var seconds = countDownTime % 60; var result = (hours < 10 ? "0" + hours : hours) + ":" + (minutes < 10 ? "0" + minutes : minutes) + ":" + (seconds < 10 ? "0" + seconds : seconds); $('.timer').html(result); if(countDownTime == 0 ){ countDownTime = 60*60*60; } countDownTime = countDownTime - 1; setTimeout(function(){ countDownTimer() }, 1000); } countDownTimer(); }); </script>
- 3 replies
-
- jquery
- javascript
-
(and 3 more)
Tagged with:
-
I have some php code that supervisors use to assign work to employees. I've added a field named clerks. There are 10 clerk names in the phpmyadmin database..clerk1, clerk2, clerk3, and so on to clerk10. I need for the clerk names to be automatically added to the clerk field in the form when it is opened..for instance, if the form is opened clerk1 is automatically inserted. And the next time it is opened, clerk2 is inserted until it reaches clerk10 & then starts over by inserting clerk1....is this possible?Like I said, I have a table in the database named clerk_names & the clerk's name is listed in this table. The database name is named flow. Any help will be greatly appreciated. Thanks
-
Hi everyone, I want to know, will Javascript's onclick on button work in PHP while loop? I mean, If I out "onclick" with function inside html tag, then put html inside echo under while loop. Will JavaScript's onclick work? Like this script below: $i = 0; while( $i < 5) { echo "<button id='btn' onclick='test()'>Hello</button>"; $i++; } This loop will create 4 times loop with same echo with onclick, so will onclick call Javascript programming?
-
In general if I know how to do something I want to do I can code it in a language I'm less than fluent in, if I am fluent in a language I can figure out how to code something I want to do but don't know very well how to do it, but this time I have almost no clue how to do what I want to do and very limited fluency in JS. I want a script that will slowly fade from one color (red, green, blue, white, black) to a neutral color (grey) and then fade into one of the randomly selected other 4 colors. Then repeat. Forever. So like Rd>gy>wt>bu>gy>bk etc. I have no clue what to do, if you can help I will be grateful for all time. Oh, and I need to make sure the text color is always contrasting so it can be read, so I need to adjust that too?
- 6 replies
-
- javascript
- css
-
(and 1 more)
Tagged with:
-
Hi I have a frame that load a php element, but I want to load at same time a javascript element. The code load correctly the php element in the frame but I can't figure out where to insert the javascript. The javascript is a slide in ads. Here is the code of the php element : <frame src="<?php echo getRandomInterstitualAdUrl(); ?>" noresize/> And here is the javascript code : <script type="text/javascript" src="http://exemple.com/adServe/banners?tid=L_16601_7&type=slider&position=bottom&animate=on&side=left&size=300x250" ></script>
- 1 reply
-
- php
- javascript
-
(and 2 more)
Tagged with:
-
Good afternoon, I am working on a project that gives the user a data table and a google chart (using the api) based on what the user selects for a <select> <option>. Index.PHP code: <form> <select name="users" onchange="showUser(this.value);drawChart();"> <option value=""> Select a Metal: </option> <?php //connection details $query = "SELECT TOP(31) tblMetalPrice.MetalSourceID, tblMetalSource.MetalSourceName from tblMetalPrice INNER JOIN tblMetalSource ON tblMetalPrice.MetalSourceID=tblMetalSource.MetalSourceID ORDER BY tblMetalPrice.DateCreated DESC "; $result = sqlsrv_query( $conn, $query); while( $row = sqlsrv_fetch_object ($result)) { echo "<option value='".$row->MetalSourceID ."'>". $row->MetalSourceName ."</option>"; } sqlsrv_close( $conn); ?> </select> </form> <div id="chart_div"></div> <div id="txtHint"><b>Past metal information will be generated below.</b></div> this works fine and generates the list in the select option dropdown Script to get table contents: <script> function showUser(str) { if (str=="") { document.getElementById("txtHint").innerHTML=""; return; } if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else { // code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("txtHint").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","scripts/gettabledata001.php?q="+str,true); xmlhttp.send(); } </script> this also works fine and generates the table contents based on 'q' value from the select dropdown. Google API script: <script type="text/javascript"> // Load the Visualization API and the piechart,table package. google.load('visualization', '1', {'packages':['corechart']}); google.setOnLoadCallback(drawChart()); function drawChart() { var jsonData = $.ajax({ url: "scripts/getgraphdata.php", dataType:"json", data: "q="+num, async: false }).responseText; // Instantiate and draw our pie chart, passing in some options. var chart = new google.visualization.LineChart(document.getElementById('chart_div')); chart.draw(data, {width: 400, height: 240}); } </script> getgraphdata.php script: $q = intval($_GET['q']); ini_set('display_errors',1); ini_set('display_startup_errors',1); error_reporting(-1); $query ="SELECT TOP(30) tblMetalPrice.MetalSourceID, tblMetalPrice.DateCreated, tblMetalPrice.UnitPrice, tblMetalPrice.HighUnitPrice, tblMetalSource.MetalSourceName FROM tblMetalPrice INNER JOIN tblMetalSource ON tblMetalPrice.MetalSourceID = tblMetalSource.MetalSourceID WHERE tblMetalPrice.MetalSourceID = '".$q."' ORDER BY tblMetalPrice.DateCreated DESC"; $result = sqlsrv_query($conn, $query); echo "{ \"cols\": [ {\"id\":\"\",\"label\":\"Date\",\"pattern\":\"\",\"type\":\"string\"}, {\"id\":\"\",\"label\":\"Unit Price\",\"pattern\":\"\",\"type\":\"number\"} ], \"rows\": [ "; $total_rows = sqlsrv_num_rows($result); $row_num = 0; while($row = sqlsrv_fetch_object($result)){ $row_num++; if ($row_num == $total_rows){ echo "{\"c\":[{\"v\":\"" . $row->DateCreated->format('d-m-Y') ."\",\"f\":null},{\"v\":" . $row->UnitPrice . ",\"f\":null}]}"; } else { echo "{\"c\":[{\"v\":\"" . $row->DateCreated->format('d-m-Y') ."\",\"f\":null},{\"v\":" . $row->UnitPrice . ",\"f\":null}]}, "; } } echo " ] }"; sqlsrv_close( $conn); When ever i try these they don't work the getgraphdata.php scripts runs fine the issue I believe but may be totally wrong may be done to the google api script that should generate the chart but doesn't. Can anyone help here I've been trying to sort this for a few days now and losing confidence in myself rapidly. Thanks Kris
- 3 replies
-
- google charts
- mssql
-
(and 3 more)
Tagged with:
-
I am a Noob at javascript so here goes. I have a slider carousel that is displayed when the webpage loads. It displays a line of images that when clicked on are displayed in larger form below it. I just want know how to automatically load (when the page firsts loads) the last uploaded on the page and then when another image is clicked from the slider carousel its loaded in its place? 2 files index and getuser.php index.php < script type="text/javascript"> jQuery(document).ready(function() { jQuery('.first-and-second-carousel').jcarousel() jQuery('#mycarousel').jcarousel({ start: 5 }); }); function showUser(str) { if (str=="") { document.getElementById("txtHint").innerHTML=""; return; } if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft\l ".XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("txtHint").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","getuser.php?q="+str,true); xmlhttp.send(); } </script> <ul id="first-carousel" class\l "="first-and-second-carousel jcarousel-skin-tango"> <li><?php $con = mysql_connect("localhost","base","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("users", $con); $sql = "SELECT * FROM contest ORDER BY member_id DESC"; $result = mysql_query($sql); while($file = mysql_fetch_array($result)){ echo '<li>'; echo '<a href="#" id="'.$file['member_id'].'" onclick="showUser(this.id)"><img src="'.$file['filelocation'].'" width="80" height="95" border="1"></a>'; echo '</li>'; } mysql_close($con); ?></li></ul> <div id="txtHint" style="text-align: center;"> </div> -------------------------------------------------------------------- getuser.php < ?php $q=$_GET["q"]; $con = mysql_connect("localhost","base","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("users", $con); $sql="SELECT * FROM contest WHERE member_id = '".$q."'"; $result = mysql_query($sql); while($file = mysql_fetch_array($result)){ echo '<div align="center" ><img src="'.$file['filelocation'].'" width="650" height="500" border="0"><br> < td>'.$file['title'].'</td><td><br> < td>'.$file['description']. '</td> < /div>'; } mysql_close(); ?>
- 1 reply
-
- javascript
- onload
-
(and 1 more)
Tagged with:
-
How to filter and show data in search without using submit button..because thats the only function i need to finish my code..can anyone help me? I dont want to use submit button cause it refreshes the page...I have the code for search already I need a function that after I search the data will show in the textboxes without using submit button. php code: <?php if($_GET){ include('include/connect.php'); $batchcode = $_GET['code']; $sql = mysql_query("SELECT aic,batchcode,address,name FROM tb_app WHERE batchcode = '".$batchcode."' "); if($sql) { while($rows = mysql_fetch_array($sql)){ $aic[] = $rows['aic']; $name[] = $rows['name']; $address[] = $rows['address']; } } }else{ $aic = array(NULL,NULL,NULL,NULL); $name = array(NULL,NULL,NULL,NULL); $address = array(NULL,NULL,NULL,NULL); } ?> html code: <html> <head> <title>test</title> </head> <body> <form action="" method="get"> Search Batchcode:<input type="text" name="code" id="query" /><br /> <table> <tr> <td> aic: <br /> <input type="text" name="optA1" value="<?php if(empty($aic[0])){$aic[0] = array(NULL);}else{echo $aic[0];} ?>" /> <br /> <input type="text" name="optA2" value="<?php if(empty($aic[1])){$aic[1] = array(NULL);}else{echo $aic[1];} ?>" /> <br /> <input type="text" name="optA3" value="<?php if(empty($aic[2])){$aic[2] = array(NULL);}else{echo $aic[2];} ?>" /> <br /> <input type="text" name="optA4" value="<?php if(empty($aic[3])){$aic[3] = array(NULL);}else{echo $aic[3];} ?>" /> <br /> </td> <td> Name List: <br /> <input type="text" name="optB1" value="<?php if(empty($name[0])){$name[0] = array(NULL);}else{echo $name[0];} ?>" /> <br /> <input type="text" name="optB2" value="<?php if(empty($name[1])){$name[1] = array(NULL);}else{echo $name[1];} ?>" /> <br /> <input type="text" name="optB3" value="<?php if(empty($name[2])){$name[2] = array(NULL);}else{echo $name[2];} ?>" /> <br /> <input type="text" name="optB4" value="<?php if(empty($name[3])){$name[3] = array(NULL);}else{echo $name[3];} ?>" /> <br /> </td> <td> Address: <br /> <input type="text" name="optC1" value="<?php if(empty($address[0])){$address[0] = array(NULL);}else{echo $address[0];} ?>" /> <br /> <input type="text" name="optC2" value="<?php if(empty($address[1])){$address[1] = array(NULL);}else{echo $address[1];} ?>" /> <br /> <input type="text" name="optC3" value="<?php if(empty($address[2])){$address[2] = array(NULL);}else{echo $address[2];} ?>" /> <br /> <input type="text" name="optC4" value="<?php if(empty($address[3])){$address[3] = array(NULL);}else{echo $address[3];} ?>" /> <br /> </td> </form> </body> </html> script code: <!--search function code--> <script type="text/javascript"> $(document).ready(function(){ $("#query").autocomplete({ source : 'search.php', select : function(event,ui){ $("#query").html(ui.item.value); } }); }); </script> search.php page code: <?php $q = $_GET['term']; mysql_connect("localhost","root",""); mysql_select_db("test"); $query = mysql_query("SELECT DISTINCT batchcode FROM tb_app WHERE batchcode LIKE '$q%'"); $data = array(); while($row = mysql_fetch_array($query)){ $data[]=array('value'=>$row['batchcode']); } echo json_encode($data); ?>
-
<p>Current Images Inside Gallery <br /> <?php foreach($rows as $row): ?> <div class="t"> <table class="table2"> <tr> <td class="table2"><?php echo $row["id"]; ?></td> </tr> <tr> <td><img src="images/<?php echo $row["photo"] ; ?>" alt="" width="130" height="130" /></td> </tr> <tr> <td><textarea class="js-copyfilename" readonly="readonly" ><?php echo $row["photo"];?></textarea> <button class="js-copyfilenamebtn">Copy Filname</button> </td> </tr> </table> </div> <?php endforeach;?> </div> <script type="text/javascript"> var copyfilenameBtn = document.querySelector('.js-copyfilenamebtn'); copyfilenameBtn.addEventListener('click', function(event) { var copyfilename = document.querySelector('.js-copyfilename'); copyfilename.select(); try { var successful = document.execCommand('copy'); var msg = successful ? 'successful' : 'unsuccessful'; console.log('Copying text command was ' + msg); } catch (err) { console.log('Oops, unable to copy'); } }); </script> I am trying to create a button so the user can copy `$filename` then paste it into a field (this part I will code after this is sorted) I have this code which works but it only works for the first row I understand that I will need array the that this is because I would probably need to array the js-copyfilename and js-copyfilenamebtn classes so each one is different but i know very little about JavaScript so would know where to start Thanks in advance