not able to get particular text box value using jquery - php

Here is my jquery function. i call this function on blue event. there are more than one records in list. i want particular rojmel_id and weight on blur event but i am not able to get. can anyone help me in this issue.
<script type="text/javascript">
function getweight(thisObj)
{
var row = $(thisObj).parents('.row');
var rojmel_id = row.find('.rojmel_id').val() != '' ? row.find('.rojmel_id').val() : 0;
var dataString = "rojmel_id=" + rojmel_id;
$.ajax({
type: "POST",
url: "updateWt.php",
data: dataString,
success: function (data){
}
});
}
</script>
Here is my html code
{section name=sec loop=$clientArray}
<tr>
<td>{$clientArray[sec].rojmel_date}</td>
<td>{$clientArray[sec].party_name}</td>
<td>{$clientArray[sec].item_nm}</td>
<td>{$clientArray[sec].marko}</td>
<td><input type="hidden" class="rojmel_id" name="rojmel_id" value="{$clientArray[sec].rojmel_id}">
<input type="text" name="weight" value="{$clientArray[sec].weight}" onblur="getweight(this);"></td>
</tr>
{/section}
</tbody>

Try this hope it work! and can you tell where you have been declared .row class.
Here is your solution: Solution JSBin
<!-- add class to <tr> then -->
{section name=sec loop=$clientArray}
<tr class="row">
<td>{$clientArray[sec].rojmel_date}</td>
<td>{$clientArray[sec].party_name}</td>
<td>{$clientArray[sec].item_nm}</td>
<td>{$clientArray[sec].marko}</td>
<td><input type="hidden" class="rojmel_id" name="rojmel_id" value="{$clientArray[sec].rojmel_id}">
<input type="text" name="weight" value="{$clientArray[sec].weight}" onblur="getweight(this);"></td>
</tr>
{/section}
</tbody>
<script type="text/javascript">
function getweight(thisObj)
{
var row = $(thisObj).closest('tr.row');
var rojmel_id = row.find('.rojmel_id').val() ? row.find('.rojmel_id').val() : 0;
var dataString = "rojmel_id=" + rojmel_id;
$.ajax({
type: "POST",
url: "updateWt.php",
data: dataString,
success: function (data){
}
});
}
</script>

Related

Laravel 5 get AJAX array POST in Controller

I have the following form:
<td>
<input type="text" name='name[]' class="form-control"/>
</td>
<td>
<input type="text" name='mail[]' class="form-control"/>
</td>
<td>
<select name="gender[]" class="form-control">
<option value="m">Male</option>
<option value="f">Female</option>
</select>
</td>
<td>
<input type="date" name='birth[]' class="form-control"/>
</td>
<td>
<input type="number" name='dni[]' class="form-control"/>
</td>
<td>
<input type="number" name='phone[]' class="form-control"/>
</td>
My ajax call when i try to submit my form
$('#form-reserve-list').on('submit', function(e) {
e.preventDefault();
var names = $("input[name='name[]']").serialize();
var mails = $("input[name='mail[]']").serialize();
var genders = $("select[name='gender[]']").serialize();
var births = $("input[name='birth[]']").serialize();
var dnis = $("input[name='dni[]']").serialize();
var phones = $("input[name='phone[]']").serialize();
var _token = $('input[name=_token]').val();
var est_id = $('input[name=est_id]').val();
var event_id = $('input[name=event_id]').val();
var url = 'http://localhost:82/boulevard/public/event/reserve/list';
$.ajax({
type: 'POST',
url: url,
data: {names:names, mails:mails, genders:genders, births:births, dnis:dnis, phones:phones, _token: _token, est_id:est_id, event_id:event_id},
cache: false,
success: function(data){
alert(data);
}
});
I want to receive this in my Controller and do a foreach or for loop and save it to my db, but the problem is when i try:
$names = Input::get('names'); //from ajax names
foreach($names as $name){
$name[];
//also tried $name[$key] after i added $key =>
}
am i doing something wrong? thank you for the help.
EDIT:
when i do alert($names) in ajax it shows as name%5B%D=carlos&name%5B%D=kevin is this the way its suppose to be? i also did dd($names); and also shows name%5B%D=carlos&name%5B%D=kevin but when i use foreach loop as mentioned above, the chrome console shows me internal error 500, am i suppose to use foreach?
EDIT2:
when i do dd(Input::all())
name%5B%5D=carlos&name%5B%5D=mendieta&name%5B%5D=cordero
how do i loop thru these?
//No need to serialize each field.
//You could do it like this:
$('#form-reserve-list').on('submit', function(e) {
e.preventDefault();
var formData = $(this).serialize();
var url = 'http://localhost:82/boulevard/public/event/reserve/list';
$.ajax({
type: "POST",
url: url,
data: formData,
dataType: "json",
success: function(data) {
},
error: function(){
alert('opps error occured');
}
});
});

Assigning AJAX response for two separate DIV tags

This is my ajax call code..
<script type="text/javascript">
$(document).ready(function(){
$('#itemcode').blur(function(){
var itemcode = $(this).val();
$.ajax({
type: "POST",
url:'ajax.php',
data: {'itemcode' : itemcode} ,
cache: false,
success: function(data) {
alert(data)
$("#desc").val(data);
$("#bal").val(data);
}
});
});
});
</script>
include "db.php";
$itemcode=$_POST['itemcode'];
$sql="select * from itemmaster where Item_Code='$itemcode'";
$result = mysql_query($sql, $con);
while($row = mysql_fetch_array($result)) {
echo $row['Item_Desc'];
echo $row['Balance_Stock'];
}
This is simple html form..
<form action="add.php" method="post">
<table style="border: 1px solid black;padding:20px;"cellspacing="1px">
</br></br>
<tr>
<td>Issue No:</td> <td><input name="issueno" type="text" id="issueno"/></td>
<td>Issue Date:</td> <td><input name="issuedate" type="date" id="issuedate"/></td></tr></br></br><tr></tr>
<tr>
<td>Item Code:</td> <td><input name="itemcode" type="text" id="itemcode" /></td>
<td>Description:</td> <td><input name="des" type="text" style="width:250px; height:23px" id="desc"/></td>
<td>Bal Quantity:</td> <td><input name="bal" type="text" id="bal"/></td>
</tr></br>
<tr> <td>Issue Quantity:</td> <td><input name="issuequ" type="text" id="issuequ"/></td></tr></br><tr></tr>
<tr><td>Remark:</td> <td><input name="remark" type="text" style="width:250px; height:23px" id="remark"/></td></tr></br>
<tr><td colspan="6"><center><input type="submit" value="submit"></center></td></tr>
</table>
</form>
When I alert(data) I am getting this samsung20.00. where samsung is description and 20.00 is bal. I want to assign description desc id an bal to bal id. So How do I do that??
In your ajax.php file, you need to use json_encode function so you can parse it after get response:
include "db.php";
$itemcode=$_POST['itemcode'];
$sql="select * from itemmaster where Item_Code='$itemcode'";
$result = mysql_query($sql, $con);
while($row = mysql_fetch_array($result)) {
$json = array("Item_Desc" = > $row['Item_Desc'],
"Balance_Stock" => $row['Balance_Stock']
);
}
echo json_encode($json);
After making adjusts that you can encode your response, Your ajax need to parse it.
Example:
<script type="text/javascript">
$(document).ready(function(){
$('#itemcode').blur(function(){
var itemcode = $(this).val();
$.ajax({
type: "POST",
url:'ajax.php',
data: {'itemcode' : itemcode} ,
cache: false,
success: function(data) {
var obj = JSON.parse(data);
$("#desc").html(obj.Item_Desc);
$("#bal").html(obj.Balance_Stock);
}
});
});
});
Its very simple.
Hope it helps you
in your php file join the value Samsung and 20.00 with || sign
include "db.php";
$itemcode=$_POST['itemcode'];
$sql="select * from itemmaster where Item_Code='$itemcode'";
$result = mysql_query($sql, $con);
while($row = mysql_fetch_array($result)) {
echo $row['Item_Desc'].'||'.$row['Balance_Stock'];
}
java script code add the var response = data.split('||'); function
<script type="text/javascript">
$(document).ready(function(){
$('#itemcode').blur(function(){
var itemcode = $(this).val();
$.ajax({
type: "POST",
url:'ajax.php',
data: {'itemcode' : itemcode} ,
cache: false,
success: function(data) {
alert(data)
var response = data.split('||');//spilt the value
$("#desc").val(response[0]);
$("#bal").val(response[1]);
}
});
});
});
</script>
<script type="text/javascript">
$(document).ready(function(){
$('#itemcode').blur(function(){
var itemcode = $(this).val();
$.ajax({
type: "POST",
url:'ajax.php',
data: {'itemcode' : itemcode} ,
cache: false,
success: function(data) {
alert(data)
var str1 = data.replace(/\d.+/g, '');
var str2 = data.replace(/[^\d.-]/g, '');
$("#desc").val(str1);
$("#bal").val(str2);
}
});
});
});
</script>

Ajax multiple input not showing all data?

I'm stuck in multiple input. My code is not showing all data. below is the html I am using:
<form id="matkul" class="form-horizontal" method="POST">
<table class="table table-condensed">
<thead>
<tr>
<th>Matakuliah</th>
<th>Data Lain</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</form>
<button id="post" type="submit">Save</button>
<button id="get">Get Data!</button>
below is the code to get the data
<script>
$(document).ready(function() {
$("#get").click(function() {
var url = 'https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url%3D%22https%3A%2F%2Funisys.uii.ac.id%2Fuii-ras%2Fmatakuliah.asp%3Fidx%3D1%26session_id%3DxxbKiKJawuyrbaaiJ3Kabybabi3JJiKJrJyb3wiuKbbry0JbKiKbKr0yyrKK15933511%26no_mhs%3D%22&format=json';
$.getJSON(url,
function(data) {
var id = data.query.results.body.table.tr.td.table.tr[2].td.table.tr;
for (var i = 1; i <= id.length; i++) {
$("<tr> <td> <input name='fmatakuliah' value='"+id[i].td[1].a.content+"'> </td> <td> <input name='fdata' value='" + id[i].td[1].a['href'] + "'> </td> </tr>").appendTo("#matkul tbody");
};
});
});
});
</script>
from the above code output will be
Matakuliah Data Lain
StringOne OtherData
StringTwo OtherData
below is the ajax post code, but when it is already sending the data, the alert does not show all the data
<script type="text/javascript">
$(document).ready(function(){
$("#post").click(function(){
string = $("form").serialize();
alert(string); // this alert is normal, show all data
$.ajax({
type: "GET",
url: "/save.php",
data: string,
success: function(data){
alert("Success!"+data); //this not normal, not show all data
}
});
});
});
</script>
below is the code on save.php
print_r($_GET);
The latest response is showing like this
Array
(
[fmatakuliah] => Wide Area Network
[fdata] => matakuliahdetail.asp?session_id=xxbKiKJawuyrbaaiJ3Kabybabi3JJiKJrJyb3wiuKbbry0JbKiKbKr0yyrKK15933511&mk=52323605&kur=2010
)
My question is how to show all data and save it to the database?
It looks like you need to change the AJAX type from GET to POST:
$.ajax({
type: "POST",
url: "/save.php",
data: string,
success: function(data){
alert("Success!"+data); //this not normal, not show all data
}
});

ajax: not getting value

i'm not getting company_name value to show_house_members.php.
but event_name can get over there. is there any error in this ajax code? i'm just a beginner in this.
$(document).ready(function() {
$("#add_mem").click(function() {
$(this).after('<div class="loader1"><img src="imgdropdown/loading.gif" alt="loading subcategory" /></div>');
var datastring = "&company_name="+$('#company_name').val()+"&event_name="+$('#event_name').val();
$.ajax({
url: 'show_house_members.php',
data: datastring,
type: 'get',
success: function(data) {
console.log(data);
$('.loader1').hide();
$("#house_members").after(data);
}
});
});
});
and here is my form
<p><label>company name</label>
<select name="company_name" id="company_name">
<?php
include("config/dbconfig.php");
$res=mysql_query("select *from tbl_company");
while($row=mysql_fetch_array($res))
{
echo "<option value=".$row[0].">".$row[1]."</option>";
}
?>
</select></p>
<!--event names dynamically added here by using jquery ajax -->
<p><label>Event name</label>
<select name="event_name" id="event_name">
</select></p>
<img title='add_house_members' src='images/button.png'/><form action="add_house_entry.php" method="GET|POST" enctype="multipart/form-data" name="f3" class="smart-green" style="width: 450px; height:290px;padding-top: 50px;padding-left: 20px;" >
<h1>Enter House details </h1>
Try to remove the & before company_name in your datastring value:
var datastring = "&company_name="+$('#company_name').val()+"&event_name="+$('#event_name').val();
// ------------- ^ remove this
you can use serialize() method to get the datastring like below
var datastring = $('#form').serialize();
it will generate datastring automatically!
Try using
data : { datastring : datastring },
Instead of
data : datastring,
Please refer to http://api.jquery.com/jquery.ajax/

jquery post form

I have this code for send simple data using jquery , but no works , all time reload de page and no load contents i send by post
My code it´s this :
<script>
$(document).ready(function() {
$("#form_order").submit( function () {
$.ajax({
type: "POST",
data : $(this).serialize(),
cache: false,
url: "indexer_adm.php?send_order2=ok",
success: function(data){
$("#load_order").html(data);
}
});
return false;
});
</script>
<form name="forma" id="form_order" method="post" action="">
<table width="100%" border="1">
<tr>
<td height="30" align="center" valign="middle">
<select name="select_order">
<option value="articles">Articles</option>
<option value="blogs">Blogs</option>
<option value="products">Products</option>
</select>
<input type="submit" name="Submit" value="Acceder">
<input type="hidden" name="send_order2" value="ok">
<input type="hidden" name="action_load" value="<?php echo $_REQUEST['action_load'];?>">
</td>
</tr>
<tr>
<td height="30" align="center" valign="middle"> </td>
</tr>
</table>
</form>
<div id="load_order"></div>
In the div called load_order , it must load the result of this send by post from the form , but the page reload and no works , i see the code many times but i don´t understand what happen
Thank´s for All
There is a syntax error in your code, you haven't closed the submit handler.
$(document).ready(function() {
$("#form_order").submit( function () {
$.ajax({
type: "POST",
data : $(this).serialize(),
cache: false,
url: "indexer_adm.php?send_order2=ok",
success: function(data){
$("#load_order").html(data);
}
});
return false;
}); // <---
});
Try returning false inside of the submit block, rather than of the ready block.
You may have a syntax error since return false should stop the form from refreshing. I would use the post function instead:
<script>
$(function() {
$("#form_order").submit( function () {
$.post('indexer_adm.php?send_order2=ok', $(this).serialize(), function(data) {
$("#load_order").html(data);
});
return false;
});
</script>
Ok !!! , Thank´s everybody
The Right code :
<script>
$(document).ready(function() {
/*
$("#load_order").show(1000);
$("#load_order").load("<?php print "".$ruta_path_adm."".$ruta_modulos."/mod_order/indexer_adm.php?send_order2=ok";?>");
*/
$("#form_order").submit( function () {
$.ajax({
type: "POST",
data : $(this).serialize(),
cache: false,
url: "<?php print "".$ruta_path_adm."".$ruta_modulos."/mod_order/indexer_adm.php?send_order2=ok";?>",
success: function(data){
$("#load_order").html(data);
}
});
return false;
});
});
</script>
Thank´s for the help i put bad the script and no see this , thank´s

Categories