Cannot Add value to the Number Using Jquery [closed] - php

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
How to Add One Value to the "0001". When I am adding one value to this number the result shows only 2.How can i get 0002?
I am using this code:
var pcode = $('#productcode').val(); // Now the pcode value is 0001
var num= parseInt(pcode) + 1;
But the result shows only 2

Just call this function after adding..
function z4(n) {
var sign = +n < 0;
n = ''+n;
while(n.length<4) n = '0' + n;
return (sign ? '-' : '' ) + n;
}
z4(2); // 0002

Related

is possible to insert data automatic process a action.php? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
EXAMPLE
I want to insert the data automatic everyday without press the button action or whatever.
In my case,
my data is ready to input every day on system but i must press the button action every day too.
thakyou
Handle an auto-click parameter in URL:
in URL: ?automode=1
in Javascript:
var is_automode = false,
$btn = YOUR_BUTTON,
$form = YOUR_FORM,
$mode = HIDDEN_INPUT_TEXT;
location.search.replace(/^\?/,'').split('&').forEach(function(val) {
var pair = val.split('=');
if (pair.length && pair[0]==='automode' && pair[1]!=0) {
is_automode = true;
}
});
if (is_automode) {
setInterval(function () {
$form.target = '_blank';
$mode.value = 'automode'; // detect this value in the target page, call window.close() if is 'automode'
$btn.click(); // or $form.submit()
}, 86400*1000);
}
Or add a cron job to open the URL (YOUR_URL/action.php?automode=1) without setInterval()

Use data from a JSON result into a table [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
Sorry for the bad titling, I had difficulty naming it.
I am trying to take this data:
<?php
require '../lib/config.php';
// Get the server statuses
$pdb = connectPDO();
$stmt = $pdb->prepare('SELECT * FROM serverlist');
$stmt->execute();
echo json_encode($stmt->fetchAll(PDO::FETCH_ASSOC));
Which gives this result:
http://ichris.xyz/ajax/server-status.ajax.php
and then take that data and insert it into a table
http://ichris.xyz/server_list.php (the table I have made to insert this data).
Use JSON DECODE: http://php.net/manual/en/function.json-decode.php
Once you serialize the json feed, then using a while or for loop run your inserts using php.
You can use
$.get('ajax/server-status.ajax.php').done(function(results) {
var statusList = $.parseJSON(results);
var tableBody = $("table tbody");
if ($.isArray(statusList)){
for(var index in statusList){
var status = statusList[index];
$("<tr>").append("<td>"+status["name"]+"</td>")
.append("<td>"+status["faction2_name"]+"</td>")
.append("<td>"+status["map"]+"</td>")
.append("<td>"+status["players_online"]+"/"+status["players_max"]+"</td>")
.append("<td>"+(status["has_password"] ? 'Yes' : 'No')+"</td>")
.appendTo( tableBody );
}
}
});
See it in action in a JSFiddle demo

How do you make color-changing text withJS? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
So, let's say I want to have a piece of text on my website, that changes color every second. I do know how to use JS to change the color of the text, but not how to continue to auto-change it based on certain parameters. For example, cycling through thousands of colors, not just one or two.
ok here is a simple way to blink text with colors
Js :
// List of colors
var spectrum = ['#f00', '#f66', '#969', '#00F', '#0FB53F'];
var cycle = spectrum.length-1;
// Cycle speed
var speed = 300;
var i = 0;
window.setInterval(function(){
document.getElementById('index').style.color = spectrum[i];
if (i < cycle) i++;
else i = 0;
}, speed);
HTML
<p id="index">Flashing text</p>
Demo
You can simple use html inside PHP:
echo "<font color='red'>Hello World</font>";
for a loop you can simple create an array with all the html collors:
$colors=array();
$colors[1]="red";
$colors[2]="blue";
// soo on....
foreach($colors as $color){
echo "<font color='$color'>Hello World</font>";
}
setInterval is what you want.
Fiddle
http://www.w3schools.com/jsref/met_win_setinterval.asp
var myColours = [...];
var index = 0;
var myElement = /*get your element*/
setInterval(function() {
/* Set your element. Are you using Javascript to get your element? */
myElement.style.color = myColours[index];
/* Are you using jQuery? */
myElement.css('color', myColours[index]);
index++;
if(index > myColours.length - 1){
index = 0;
}
}, 1000);

Autonumber in inputting new records [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
My patient number(pnum) need to have a autonumber, like BLHC-2014-0001. I need to automatically have the BLHC-current year-and auto increment of the number with 4 digits when i input new record.
function autonum(){
var c ='BLHC-2014-0001';
var d = c.split("-");
var e = d[2];
var f = parseInt(e,10);
var g = f+1;
var str = '' + g;
var pad = "0000";
var resu = str.length < 4 ? (pad+str).slice(-4) : str;
var lt = d[0]+'-'+d[1]+'-'+resu;
document.getElementById("pnum").value =lt;
}

I figure it out myself [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
in the updates.. with my code above, it is working if i only choose 1 row but when i have chosen more than 1 row, the value in the last row that i inserted is the only value that mysql is using to updates all rows. 2 yes it is intended. i need it for my updates, 3rd sorry, but i am using CSS though i will clean my code after i finish my program, im just stack here
This is my parent window HTML code
JAVASCRIPT
function MM_openBrWindow(theURL,winName,features) { //v2.0
var chkValue = "";
var counter = "";
for (var i=0; i < document.myForm.chkbox.length; i++)
{
if (document.myForm.chkbox[i].checked)
{
chkValue = chkValue + document.myForm.chkbox[i].value + " ";
}
counter ++;
}
var queryString = "&chkValue=" + chkValue;
// location = "featuredaction.php" + queryString
//var queryString = "id=" + id;
var theURL = theURL + queryString;
//var tbreceiptno= document.getElementById('checkbox').value;
window.open(theURL,winName,features);
}
I think i will fgure it out my own thanks everyone..
You have fault in your second line $chkValueArr=explode(" ", $chkValue);. You dont have to explode it. You already got an Array of checkbox value when you wrote $chkValue=$_GET['chkValue']; Assuming your HTML form is something like:
<input type="checkbox" name="chkValue[]" value="val 1">
<input type="checkbox" name="chkValue[]" value="val 2">
<input type="checkbox" name="chkValue[]" value="val 3">
You can loop over all checkbox values by:
foreach($chkValue as $chk)
{
echo $chk;
}
This will print val 1, val 3 if you selected those checkboxes in your form.
You can check the array by writing print_r($chkValue)

Categories