i'm using jquery tabs..
i'm use tabs-1 as input form and tabs-2 as show input data...
i want after submit..all value inside textfield which have been type at tabs-1 can copy into textfield at tabs-2...
where part that i must modify?at form or at process page?what's code that can make it works?
<script type="text/javascript">
$(document).ready(function() {
$("#input").click(function() {
if($("#submit").valid()) {
var params=$("#submit").serialize();
$.ajax({
type:"post",
url:"process1.php",
data:params,
cache :false,
async :false,
success : function() {
that is for submitting form inside tabs-1...at tabs-2:
<tr>
<td width="100"><input type="text" id="showline" name="showline"<? echo "$_postVar('line')" ?>/></td>
<td width="100"><input type="text" id="showmodel" name="showmodel"<? echo "$_postVar('model')" ?>/></td>
<td width="100"><input type="text" id="showNIK" name="showNIK"<? echo "$_postVar('id')" ?>/></td>
</tr>
Well, if I understand this correctly, you can use the callback on the AJAX function to do that (so that the submitted info is only displayed if the request was successful):
[...]
success : function() {
$('#showline').val($('#faline').val());
$('#showmodel').val($('#modelnm').val());
$('#showNIK').val($('#NIK').val());
};
[...]
assuming that #faline, #modelnm and #NIK are the IDs of the input fields in the form from which the data is being submitted.
Also, in the HTML you don't need to echo anything anymore (which has incorrect syntax - it would be value="<? echo ... ?>" anyways) since the values will be added by jQuery.
Hope this helps !
$("#model").change(function() {
var barcode;
barCode=$("#model").val();
var data=barCode.split(" ");
$("#model").val(data[0]);
$("#serial").val(data[1]);
var str=data[0];
var matches=str.match(/[T|EE|EJU].*D/i);
$("#input").click(function() {
if($("#submit").valid()) {
var params=$("#submit").serialize();
$.ajax({
type:"post",
url:"process1.php",
data:params,
cache :false,
async :false,
success : function() {
$('#showline').val($('#line').val());
$('#showmodel').val($('#model').val());
$('#showNIK').val($('#id').val());
$("#model").val("");
$("#serial").val("");
$("#line").val("");
i put freekOne code before set .val("");
Related
I'm trying to use ajax within my submit form in a codeigniter. I have it to where the ajax call is made, bu the validation errors are not displaying. I can't figure out why. Please help.
I do have some returns in there, but they do nothing.
if ($this->form_validation->run() == FALSE)
{
echo(json_encode("validate"=>FALSE));
}
else
{
$this->load->model('adduser_model');
$data['query']=$this->adduser_model->adduser();
}
}
view code:
<script>
//CHECKS ONE FIELD AT A TIME
$(function(){
$(".field").each(function(){
$(this).keyup(function(){
var id = $(this).attr("id"); //VALUE OF INPUT ID Ex: <input id="name">
var v = $(this).val(); //INPUT TEXT VALUE
var data = id+"="+v; //DATA TO GO TO THE AJAX FILE Ex:(name=wcet)
$.ajax({
type: "POST",
url: "prog/validate", //AJAX FILE
data: data+"&single=true",
success: function(e){ //"e" IS THE DATA FROM "validate.php"
$("span#"+id).html(e); //ECHOS DATA FROM "validate.php" NEXT TO THE INPUT IF NEEDED
}
});
});
});
});
</script>
<BODY>
<?php $this->load->helper('form');
echo form_open('prog/validate'); ?>
<tr><td align="right">Name: </td><td align="left"><input class="field" name="name" id="name"> <span id="name"></span><br></td></tr>
<tr><td align="right">email: </td><td align="left"><input class="field" name="email" id="email"> <span id="email"></span><br></td></tr>
If you have some returns that means the function was successful. Even if you didn't have the response you expected, the $this->form_validation->run() will be false ONLY if the $ajax call couldn't fire at all (404, 500 errors).
You can also trying catching the error via failure: function () {}, for example:
$.ajax({
type: "POST",
url: "prog/validate", //AJAX FILE
data: data+"&single=true",
success: function(e){ //"e" IS THE DATA FROM "validate.php"
$("span#"+id).html(e);
},
failure: function(e) {
// check against error messages
}
});
i try to submit text to db, but in the db field not inserted any text.
can you analyze where my false?
i try like this.
Thanks for your help.
<script type="text/javascript">
$(document).ready(function() {
$('#myForm').submit(function() {
var namaklasifier = document.getElementByName("tfklasifier").value;
var inputpos= document.getElementByName("tacaripos").value;
var inputnet = document.getElementByName("tacarinet").value;
var inputneg = document.getElementByName("tacarineg").value;
$.ajax({
type: 'POST',
url: $(this).attr('action'),
data: $(this).serialize(),
success: function(data) {
$('#resultcoba').html(data);}
})
return false;
});
})
</script>
<form id="myForm" method="post" action="proses.php">
<td align="center" valign="top" style="width:420px"><textarea style="width:420px" name="tacaripos" rows="4" cols="70"><?PHP echo htmlspecialchars($_POST['tacaripos']);?></textarea></td>
<td align="center" valign="top" style="width:420px"><textarea style="width:420px" name="tacarinet" rows="4" cols="70"><?PHP echo htmlspecialchars($_POST['tacarinet']);?></textarea></td>
<td align="center" valign="top" style="width:420px"><textarea style="width:420px" name="tacarineg" rows="4" cols="70"><?PHP echo htmlspecialchars($_POST['tacarineg']);?></textarea></td>
</tr>
<td align="center"><input type="submit" name="btklasifier" id="btklasifier" value="Buat" /></td></form>
proses.php
<?php
$namaklasifier=$_POST['namaklasifier'];
$jadipos=$_POST['inputpos'];
$jadinet=$_POST['inputnet'];
$jadineg=$_POST['inputneg'];
$link=mysqli_connect("localhost", "root", "","skripsi");
mysqli_select_db($link,"skripsi");
mysqli_query($link,"INSERT INTO namaklasifier(username,datapos,datanet,dataneg,user) VALUES('$namaklasifier','$jadipos','$jadinet','$jadineg','{$_SESSION['username']}')"); ?>
Thanks :)
You are trying to access the GET data under the variable names you have declared here:
var namaklasifier = document.getElementByName("tfklasifier").value;
var inputpos= document.getElementByName("tacaripos").value;
var inputnet = document.getElementByName("tacarinet").value;
var inputneg = document.getElementByName("tacarineg").value;
Yet you are sending them using $(this).serialize() which means you must access the GET variables using the input name as this is what serialize does (creates an object from the form elements using their names). e.g.
$jadipos=$_POST['tacaripos'];
$jadinet=$_POST['tacarinet'];
$jadineg=$_POST['tacarineg'];
Also you need to change $_GET to $_POST as that is the method you are using.
In proses.php, change the $_GET into $_POST.
Since you are using POST method to submit data, naturally, you have to use the $_POST variables.
They are POST values not the GET ones
$jadipos=$_POST['inputpos'];
$jadinet=$_POST['inputnet'];
$jadineg=$_POST['inputneg'];
And try to use mysqli_* functions or PDO statements,instead of mysql_* functions due to they are deprecated
EDIT:also try like
var namaklasifier = document.getElementByName("tfklasifier").value;
var inputpos= document.getElementByName("tacaripos").value;
var inputnet = document.getElementByName("tacarinet").value;
var inputneg = document.getElementByName("tacarineg").value;
$.ajax({
type: 'POST',
url: $(this).attr('action'),
data: {inputpos:inputpos,inputnet:inputnet,inputneg:inputneg},
success: function(data) {
$('#resultcoba').html(data);}
})
return false;
});
Can you ajax post a single input from a form with a seperate form ajax function than the forms submit? I am trying to delete a table row within a form, without submitting the entire form.
particular Row hide from table... Display wise that row is removed..
$("#row"+i).animate({"height": "toggle"}, { duration: 1000 });
Next ajax function calls for deletion..
You need to access the row in jQuery and call remove on its object.
Live Demo
$('#rowId').remove();
You can use jQuery ajax to call php function with javascript, this post shows how to do it.
Yes you can send ajax post request via jquery.
Guidance code is as below.
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function()
{
$('.delete_link').click(function(e){
e.preventDefault();
var href = $(this).attr('href');
var main_selector = $(this);
$.ajax({
url : href,
type : 'post',
dataType : 'json',
beforeSend : function()
{
//code before ajax send
},
success : function(response)
{
if(response)
{
main_selector.parent().remove();
}
}
});
});
});
</script>
<table>
<tr>
<td>Data1</td>
<td></td>
</tr>
<tr>
<td>Data2</td>
<td></td>
</tr>
<tr>
<td>Data3</td>
<td></td>
</tr>
</table>
I have been trying to submit a form with jquery ajax but have been having issues.
When i check through firebug i see the value posted but it shows error from the url. I have this html
<form method="post" name="tForm" id="tForm">
<table>
<tr>
<td>Age</td>
<td><input name="age" id="age" value="" /></td>
</tr>
<tr>
<td><input type="button" id="submit" value="submit"/></td>
</tr>
</table>
</form>
</body>
My js file that submits the form has this piece of code
$(document).ready(function() {
$('#tForm').submit(function(){
var age = $('#age').val();
var msg ='';
$.ajax({
url:'testp.php',
type:'post',
data: {age:age},
beforeSend:function(){
alert(age);
},
success:function(data){
msg=data;
alert(msg);
},
complete:function(){
alert(msg);
}
})
})
});
My testp.php file just has this
<?php
echo 'ok';
?>
You need to stop the event from propogating. Your form attempts to submit in the standard method and since your form doesn't have an action you receive the error.
$(document).ready(function() {
$('#tForm').submit(function(){
var age = $('#age').val();
var msg ='';
$.ajax({
url:'testp.php',
type:'post',
data: {age:age},
beforeSend:function(){
alert(age);
},
success:function(data){
msg=data;
alert(msg);
},
complete:function(){
alert(msg);
}
})
return false;
})
});
Use $('#tForm').submit(function(e){ ... and then call e.preventDefault(); to prevent the form from being submitted in a regular (non-ajax) request.
However, I'd suggest you to have a look at the jQuery form plugin which saves you some work.
I'm writing a store system for my game,
it worked quite well until I found out that it only takes the amount of first entered Item.
function pbuy(buyitem) {
var amountc = "amount-"+buyitem,
var amount = $("#"+amountc+"").val();
$.ajax({
type: "POST",
url: "store2.php",
data: "buyitem="+ buyitem+"&amount="+amount,
success: function(resp){
document.getElementById('ajaxDiv').innerHTML = resp;
},
error: function(e){
alert('Error: ' + e);
}
});
}
I'm trying to give it it the Id of the form like so:
function pbuy(buyitem) { var amountc = "amount-"+buyitem, var amount = $("#"+amountc+"").val();
But nothing happens.
The code the creation of the forms is:
<tr>
<td class='items' width='80%' align='center' valign='top'>
<?PHP echo $itemstore->itemname;?>
</td>
<td width="20%">
Price:<?PHP echo $itemstore->newprice;?>
<form method="post">
<input type='text' id='amount-<?PHP echo $row;?>)' />
<input name="itembid" type="button" onclick="pbuy(<?PHP echo $row;?>)" value="Buy" />
</form>
</td>
</tr>
If I hardcode the amount in the ajax function it all runs fine like it should.
You're getting a javascript error before the AJAX-request is being sent since you are defining your amountc and amount variables separated by a comma. Either do
var amountc = "amount-"+buyitem;
var amount = $("#"+amountc+"").val();
semicolon separated, or keep the comma and skip the second var
var amountc = "amount-"+buyitem,
amount = $("#"+amountc+"").val();
Did you checked the response of the AJAX request?