last day (15 days later) » 

7:18 AM
Hi Manoj
 
Hi Piyush
 
Are you comfortable in English, we can also talk in Hindi if you want
 
I dont know hindi. Im from Tamilnadu. lets talk in hindi
 
You have any link of your page?
Also are you implementing this in your theme or a plugin?
 
Im working in local
yes. im implementing in plugin
 
7:26 AM
good, your custom plugin or customizing any plugin?
 
no. i created new plugin for a website
pls check this code
 
ok you have js file in it?
 
Paste this in it
jQuery(function($) {
$(document).ready(function(){
$('#mySelect').on( 'change' , function(){
var newValue = $(this).val();
$.ajax({
type: 'POST',
url: ajax_params.ajax_url,
dataType: 'json',
data: {
action: 'yourFunction',
newValue: newValue
},
success: function(response) {
console.log(response);
},
error: function(errorThrown){
console.log(errorThrown);
}
})
})
})
});
ajax_params.ajax_url
 
this my code
jQuery.noConflict();
(function($){
$(function() {

$("#mySelect").change(function(){

var val = jQuery(this).val();
var ajaxurl = ajax_object.ajaxurl;
jQuery.ajax({
url: ajaxurl,
type: "POST",
data: {
action: "keyword_analyzer_form", //your action name
val: val
},
dataType : "json",
success: function(data, textStatus, jqXHR){
alert(data);


}
});
});

});
})(jQuery);
 
7:29 AM
ok show me where is your wp_enqueue
and keyword_analyzer_form() function
 
add_action( 'wp_ajax_keyword_analyzer_form', 'strideup_keyword_analyzer_insert_data' ) ;
add_action( 'wp_ajax_nopriv_keyword_analyzer_form', 'strideup_keyword_analyzer_insert_data' );

function strideup_keyword_analyzer_insert_data(){
global $id_val;
$id_val = ($_POST['val']);
}
how to use variable inside the function "strideup_keyword_analyzer_insert_data()" in other function?
this my question
 
why not work inside this?
 
I want to retrieve database based on this variable
 
you can call otherFuntion($id_val) inside your stride_up function if you want to
add_action( 'wp_ajax_keyword_analyzer_form', 'strideup_keyword_analyzer_insert_data' ) ;
add_action( 'wp_ajax_nopriv_keyword_analyzer_form', 'strideup_keyword_analyzer_insert_data' );

function strideup_keyword_analyzer_insert_data(){
global $wpdb;
$id_val = ($_POST['val']);
$result = Query here
return json_encode($result);
}
 
pls send example code
shall we chat after 30 min?. i have to go.. sorry
 
7:36 AM
i don't know what you want to query with $id_val
 
i want to use $ID_VAL in this query .. $results[$id_val]->area_name;
 
What is $results which table what are the fields, dont know anything
$results = $wpdb->get_results( "SELECT * FROM $table_name" WHERE your_field='$id_val');
when you are back post the function in which you want to use $id_val
 
 
1 hour later…
8:52 AM
i want display database data based on select option.. $id_val is id of the selected option. using that id , i trying to retrieve the field value based on id..These are my field in databse area_name, area_code, order_value, delivery_charge,delivery_time.
Are you there??
 
9:12 AM
post your function
 
9:24 AM
function get_table1(){
?>
<span id="mySelect1">
<?php

?>
</span>

<select id="mySelect" name="taskOption">
<option>Choose Your Area</option>
<?php
global $wpdb;
$table_name = $wpdb->prefix . 'pop_up_db';
$results = $wpdb->get_results( "SELECT * FROM $table_name");
foreach ( $results as $result ) {
echo '<option value="'.$result->id.'">'.$result->area_name.'</option>';
}
?>


</div>

<div>
echo ' Your Selected Delivery Area : '.$results[$_POST['val']]->area_name.'<br />';
</div>

<?php
}
 
You are completely on a wrong path
 
function get_table1(){
?>
<select id="mySelect" name="taskOption">
<option>Choose Your Area</option>
<?php
global $wpdb;
$table_name = $wpdb->prefix . 'pop_up_db';
$results = $wpdb->get_results( "SELECT * FROM $table_name");
foreach ( $results as $result ) {
echo '<option value="'.$result->id.'">'.$result->area_name.'</option>';
}
?>
</select>

</div>

<div>
echo ' Your Selected Delivery Area : '.$results[$_POST['val']]->area_name.'<br />';
</div>

<?php
}
What i want to do now?
 
what is the table name from where you want results, is it "pop_up_db"
 
yes. The table name is pop_up_db
 
why are u using ajax?
u just want to display the selected value?
 
9:32 AM
Selected value is the id of database. Im getting id using ajax.
 
What is this?
Your Selected Delivery Area : '.$results[$_POST['val']]->area_name.
You want something like this codepen.io/faizalheesyam/pen/tEvIg
 
if this code is like is " $results[1]->area_name, it will display 1st value stored in database under area_name coluomn
@PiyushRawat yes.. But data should be retrieved from db
 
echo '<option value="'.$result->area_name.'">'.$result->area_name.'</option>';
And append this value on change in the deliver message
Why to work with Databse?
you are going in wrong direction
This is easily achievable without ajax
 
how to do without ajax?
 
w8 i will update you
 
9:40 AM
ok
 
function get_table1(){
?>
<select id="mySelect" name="taskOption">
<option>Choose Your Area</option>
<?php
global $wpdb;
$table_name = $wpdb->prefix . 'pop_up_db';
$results = $wpdb->get_results( "SELECT * FROM $table_name");
foreach ( $results as $result ) {
echo '<option value="'.$result->area_name.'">'.$result->area_name.'</option>';
}
?>
</select>

</div>

<div>
<p class="deliveryMessage"></p>
</div>

<?php
}

$(document).ready(function(){
$('#mySelect').on('change', function(){
var value = $(this).val();
 
this code will display only area_name.. I need to display area_code, order_value, delivery_charge,delivery_time.
 
of the current selected place only, right?
 
this is example site. eseafoods.in
 
i can't do the complete code for you brother. This code will work for every field you add
add
data-area="'.$result->area_code.'"
inside your <option>
and catch it like
var area_name = $(this).data('area_name');
in your script
then append anywhere you want
I gotta go now
 
9:48 AM
ok thanks brother
 

last day (15 days later) »