is it possible that when nepali date is inserted on one textbox will be changed into eng date and be seen on other text box without refreshing any page?
i have a function on PHP that changes nep date to eng and vice-versa i just want that to be run on the particular textbox when anyone inserts nepali date on other textbox
i call my function for changing date is
PHP Functions
NepToEng()
EngToNep()
HTML Elements
<input type="text" name="dobnep" size="26" maxlength="300" />
<input type="text" name="empdobeng" size="26" maxlength="300" />
Scenario :
when anyone writes nepali date of birth on dobnep will be converted into english and be shown on empdobeng
var input1 = $('[name="dobnep"]'),
input2 = $('[name="empdobeng"]');
input1.on('keyup', function() {
NepToEng(this.value).done(function(data) {
input2.val( data );
});
});
input2.on('keyup', function() {
EngToNep(this.value).done(function(data) {
input2.val( data );
});
});
function NepToEng(val) {
return $.ajax({
url : 'link/to/script_that_converts_to_eng.php'
data: {date: val}
});
}
function EngToNep(val) {
return $.ajax({
url : 'link/to/script_that_converts_to_nep.php'
data: {date: val}
});
}
I would highly suggest reimplementing those functions in Javascript, otherwise you could be making a lot of HTTP requests to your server and degrading the performance of your application for what I imagine is a simple calculation that a browser could handle very quickly.
PHP functions cannot be executed based on user actions. One solution is to use Ajax function that sends the value of dobnep and retrieves its empdobeng in english.
there you go...if you have the entire functionality ready,You just need a little bit of ajax magic in your code.
fetch the value of your engDATE(lets say FETCHED_VALUE) and in responsetext of ajax put this code,
document.getElementById(id).value="FETCHED_VALUE"
note:allot an id for the text box with name=empdobeng and use function keyup
this was my code and it helped me... which i mixed
Javascript
function add() {
num1=$("#dobnep").val();
$.ajax({
type: "POST",
url: "change.php",
data: "dobnep="+num1,
success: function(html){
document.getElementById('empdobeng').value=html;
}
})
}
HTML
<input type="text" name="dobnep" id="dobnep" onblur="add()" size="26" maxlength="300" />
<input type="text" name="empdobeng" id="empdobeng" size="26" maxlength="300" />
PHP
$date=UTF8toEng($_POST['dobnep']);
echo EngtoUTF8(NepToEng($date));
Related
I have a text-area which saves the data in my database every-time the user hits a key or writes inside the text-area . My problem is that when i want to show a success message like "saved" in a <p> it repeats itself every-time someone hits a key, i want it to repeatedly show the same message under but only one time.
If possible may remove the "saved" message on success after 10 seconds.
This is what i mean:
HTML:
<div class="form-group">
<label for="comment">Kommentar:</label>
<textarea class="form-control" rows="5" id="comment" name="comment"></textarea>
<p name="message" id="message"></p>
jQuery:
$("#comment").keyup(function (){
var isTyping = $('#comment').val();
var data = 'result=' + isTyping;
$.ajax({
type: 'POST',
url: "commentsave.php",
data: data,
cache: false,
success: function(html){
$('#message').append('Saved');
}
});
});
PHP:
$name = $_POST['result'];
echo $name;
Thank you very much, dont need you to code for me but just guide me :)
Change:-
$('#message').append('Saved');
to:-
$('#message').html('Saved');
Note:- append() added the new data into the existing-one inside an element, that's why multiple successful messages shown.
While html() will remove old data from element first and then add new-one. So no-repetition will happen.
Please try to read every comment under your post and try to implement them for improvement.Specially not sending ajax call on each key-up. It will broke your system at-some point of time.
So i'm a completely rookie at AJAX so I was wondering if someone could help.
I'd like to get this, SQL command to be activated onkeyup:
SELECT * FROM commands WHERE tag=$_POST['search_input']
This is the current code I have for the form:
<form method="post">
<input class="search_input" type="text" name="search_input" placeholder="Search..." onkeyup="suggest()" autocomplete="off" />
</form>
Current jQuery:
$(document).ready(function() {
$('.search_input').keypress(function(event) {
if (event.keyCode == 13) {
event.preventDefault();
}
});
function handleKeyPress(e,form){
var key=e.keyCode || e.which;
if (key==13){
form.submit();
return false;
}
}
});
the function suggest() is what I'd like your guy's help on. To send the command above on a keypress.
Use $.post(). You have here examples http://api.jquery.com/jquery.post/
The basic structure is
$.post(url(string), data(object), function(response){ /* do something */ });
A delay between inputs would be really good so it won't continuously send requests to the server. You may also want to use keyup instead of keypress, test it and you'll see why.
I would recommend to use...
HTML
<form method="post">
<input class="search_input" type="text" name="search_input" placeholder="Search..." autocomplete="off"/>
</form>
JS
// shorthand for document ready
$(function(){
var $input = $('.search_input');
// using on-function (see jQuery Docs)
// bind event instead of using on-attribute (nicer)
// bind input event instead of keyup, because it will fire on paste too
$input.on('input', function(evt){
$.ajax({
// maybe use GET?
type: 'POST',
url: '/yourQueryPath',
// assign the input value to the needed query parameter
data: {'search_string': $input.val()},
success: function(response){
// whatever you want to to with your response
}
)};
});
});
Additionally a hint: Never use unfiltered user input like your SQL does (MySQL-Injection)!
E.g. if you are with PHP please use filter_input() and mysql_real_escape_string() or simliar.
i am using this http://multidatespickr.sourceforge.net/#method-addDates to enable multiple date select. everything works fine but i am wondering how to get the selected dates to PHP.
below is the html code.
<input type="text" name="outgoing_call_dates" value="" id="outgoing_call_dates_id" class="hasDatepicker">
as you can see value tag is empty always when i add, its normally appending to the end but not value tag is doing the same. please check this image.
Original source : http://multidatespickr.sourceforge.net/#method-addDates (example : From input)
Please help me find a way
HTML
<input id="datePick" type="text"/>
<input id="get" type="button" value="Get" />
JS
$('#datePick').multiDatesPicker();
$('#get').on("click",function(){
var dates = $('#datePick').val();
if(dates !=''){
dataString = 'dates='+dates;
$.ajax({
type:"POST",
url : "URL_TO_PHP_FILE",
data : dataString,
dataType : 'json',
success : function(data) {
alert(data);
}
)};
}
});
PHP
$dates = ($_POST['dates']);
echo json_encode($dates);
value attribute defines default value. If you change the value of input element, it won't be inside source with value="YOUR_ENTERED_VALUE" .
To access value in client side, you can use JS or jQuery.
For example using jQuery:
var dates = $('#outgoing_call_dates_id').val();
In pure JS:
var dates = document.getElementById('outgoing_call_dates_id').value;
For PHP,
when you'll receive it on your action page.
On that page,
use this:
$dates = $_POST['outgoing_call_dates'];
or
$dates = $_GET['outgoing_call_dates'];
depending on the method you use.
Please have a look # this....!
Hope this will fix your issue :)
<no codes :|>
http://jsfiddle.net/3t4j9/23/
I have a table that generates perfectly using php, ajax and the tablesorter plugin. I now would like to make a few of the input fields into dropdown boxes so the user can select an option if it needs to be changed. This all will then need to be saved to a database. Here is what I have so far:
$('#getInfo').live('click', function() {
//clear table before search
$("#inventoryUpdate tbody tr").remove();
$('#messageInv').html('Please be patient, this might take a minute');
$.ajax({
type: "POST",
async: true,
url: "getInventory.php",
dataType: "json",
data: ({skuStart: $("#startSkuRange").val(), skuEnd: $("#endSkuRange").val(), processDate: $("#processDate").val(),
source: $("#source").val()}),
success: function(data){
$('#messageInv').hide();
//console.log(data);
var myselectoptions = '';
if(data.isbn2 === null){
$("#inventoryUpdate").append('<tr><td>No Records Found</td></tr>');
}else{
for(var x=0;x<data.isbn2.length;x++)
{
$.each(data.defect2[x], function(index, val)
{
myselectoptions += '<option value="'+data.defect2[x][index].option+'">'+data.defect2[x][index].option+'</option>';
});
$("#inventoryUpdate").append('<tr><td id="tableSKU">'+data.sku[x]+'</td><td id="tableISBN">'+data.isbn2[x]+
'</td><td><input type="text" id="tableQuantity" value="'+data.quantity[x]+
'"/></td><td><select id="tableDefect">'+myselectoptions+
'"</select></td><td><input type="text" id="tableSource" value="'+data.source[x]+
'"/></td><td><input type="text" id="tableFeature" value="'+data.feature[x]+
'"/></td><td><input type="text" id="tableLocation" value="'+data.location[x]+
'"/></td><td><input type="text" id="tableProcessDate" value="'+data.processDate[x]+
'"/></td><td><input type="text" id="tableBookType" value="'+data.booktype[x]+
'"/></td><td><input type="text" id="tableCreatedBy" value="'+data.created[x]+
'"/></td><td><input type="text" id="tableModifiedBy" value="'+data.modified[x]+
'"/></td></tr>');
}
$("#inventoryUpdate").trigger("update");
} // end of else statement
} // end of success function
});// end of ajax call
}); // end of inventory update function
I would like to have the tableDefect and tableFeature inputs become drop down boxes that are populated dynamically, and default to the current info from the database. For example, if the defect from the database is "rip in dust jacket" that would be the option that is selected, but I also need the rest of the options (no defects, water damage etc.) from the database to be available if it needs to be changed. I would think that I need to change the input type to a select, but then how do I go about populating it? Would that require another call to the database for the information?
Is this even possible to do with this plug-in?
EDIT: I have pasted in the new code based on the answer below, I now am getting 19 "options" (it just says undefined not the actual value returned) for the first record, 38 for the second etc. There should only be 19 options.
If I am reading you correctly just replace <input type="text"......> with
<select id=...><option>...</option></select>
As far as populating the selects dynamically that can be handled a few different ways. With your ajax you would get the select values maybe by changing your existing
data.defect[x] into a multidimensional object so instead of it being just a string you would output an array that will get converted to JSON on your backend so your object would look like
defect[{"option":"value"},{"option":"value"},{"option":"value"},{"option":"value"}]
Where when your building your table in the succession part you would loop over that object. You would essentially do the same as you do now.. except. your select would look like
var myselectoptions = '';
$.each(data.defect[x], function(index, val)
{
myselectoptions += '<option value="'+data.source[x][index].option+'">'+data.source[x][index].option+'</option>';
});
'"/></td><td><select id="tableDefect">'+myselectoptions+'....
now this is pure concept, I haven't tested it, and its likely to need some tweaking to fit your needs specifically but this is the core concept of one of a few ways you can handle what you want done, that fits into what you are currently doing, without having to alter it too much.
i am creating a few input fields in a foreach loop:
<?php foreach($this->results as $value){?>
<td>View Detail
<input name="processor" id="processor" type="text" value="<?php echo $value['processor']; ?>">
<input name="auth_code" class="auth_code" type="hidden" value="<?php echo $value['auth_code']; ?>"></td>
<? } ?>
is will give me something like:
<td>
View Detail
<input name="processor" class="processor" type="text" value="19">
<input name="auth_code" class="auth_code" type="text" value="4">
</td>
<td>
View Detail
<input name="processor" class="processor" type="text" value="9">
<input name="auth_code" class="auth_code" type="text" value="11">
</td>
...
then i try to get the values:
$('.buttonDetails').live("click", function (){
var processor = $('.processor').val();
alert(processor);
$.ajax({
type: 'POST',
dataType: 'json',
url: '/decline/list',
async: false,
data: {
processor: processor,
processor: auth_code
},
success: function(json) {
$('#details').html(json.processor);
}
});
return false;
});
the problem i have is that my alert gets the same number (usually the first value from the first input) when i click on any link.
any ideas ho to fix this? i've tried replacin classes with id's and 'click' with 'live' but still nothing
edit:
i believe i need to differentiate the classes so he links will know what value to pull..??
edit: what if i want to get the 'auth_code ' also?
Try:
$('.buttonDetails').live("click", function (){
var processor = $(this).next(".processor").val();
alert(processor);
/* snip */
});
Use next to get the input next to the link that was clicked.
Update (due to comment).
You could find auth_code similarly using nextAll instead:
var auth_code = $(this).nextAll(".auth_code").val();
Also, are you sure you're supplying the correct values to your AJAX call? It looks like you're specifying processor twice. The first value specified for processor will be overwritten.
If you just want the next item you can use jquery next()
$('.buttonDetails').live("click", function (){
var processor = $(this).next().val();
alert(processor);
return false;
});
here is a fiddle
http://jsfiddle.net/znge4/1/
data: {
processor: processor,
processor: auth_code
},
the 'auth_code' line will overwrite the 'processor' line, effectively making it
data: {
processor: auth_code
},
only. You can't have a single key with two different values in a associate array/object. For submitting same-name fields to PHP, use its fieldname[] notation, which tells PHP to treat that particular form field as an array.
<input name="processor[]" ...>
<input name="processor[]" ...>
and pass the data to JQuery via
data : $(this).serialize()
use Jquery .next() which should give you the next element
You get the same value no matter which anchor tag was clicked because of this line:
var processor = $('.processor').val();
You're searching the entire DOM for all elements with class 'processor', which returns every input, and then .val() will return the value of the FIRST match (the first input).
Try this instead:
var processor = $(this).next('.processor').val();
All you need to do is get the value from the element they clicked. Using Jquery's 'this' keyword should solve your problem.
$('.buttonDetails').live("click", function (){
var processor = $(this).next().val();
alert(processor);
The 'this' will select the 'a' they clicked on, then next will iterate to the next sibling, in this case your input, and the val retrieves that value as before.