my code works fine for the first list. But not work even other list if has more list. Could you please find out what happened with my code.
if I click on signOut it will be add to database and remove form the page with signOut value only. First Div list work,But other will not response anything.
Thank You
Here is my code:
Java Script Code:
$(function() {
$("#add").click(function(){
//Save the link in a variable called element
var element = $(this);
//Find the id of the link that was clicked
var del_id = element.attr("dataid");
var outime = $(this).parents("#list").find("#outtime").val();
//Built a url to send
var info = 'id=' + del_id+ '&singout=' + outime;
$.ajax({
type: "POST",
url: "signOut.php",
data: info,
success: function(){
}
});
// After success
$(this).parents("#list").animate({ backgroundColor: "#fbc7c7" }, "fast")
.animate({ opacity: "hide" }, "slow");
});
});
HTML COde:
<?php
$comments = runQuery($conn, "SELECT * FROM `civ_in_out` WHERE `out_time` = 'null'");
//print_r($comments) ;
if(!empty($comments)) {
foreach($comments as $k=>$v) {
?>
<div id="list">
<div class="form-group">
<div class="form-row">
<div class="col-md-3">
<input class="form-control" type="text" name="name" value="<?php echo $comments[$k]['name']; ?>" disabled>
</div>
<div class="col-md-3">
<input class="form-control" type="time" name="signIn" value="<?php echo $comments[$k]['in_time']; ?>" disabled>
</div>
<div class="col-md-3">
<input class="form-control" id="outtime" type="time" name="singOut">
<input class="form-control" id="id" type="hidden" name="id" value="<?php echo $comments[$k]['id']; ?>">
</div>
<div class="col-md-3">
<a class="btn btn-primary btn-block" dataid="<?php echo $comments[$k]['id']; ?>" id="add" >Sign Out</a>
</div>
</div>
</div>
</div>
<?php
} }
?>
signOut.php
include 'connect.php';
$data=$_POST['serialize'];
echo $id = $data['id'];
echo $outtime = $data['singout'];
$sql = "UPDATE `civ_in_out` SET `out_time`='$outtime' WHERE id = '$id'";
mysqli_query($conn, $sql);
The problem is that you are repeating the list id and all the other element ids, so the jQuery call and event binding will always refer to the first id found on the HTML.
Id’s must be unique on you html.
You can change your code to use a class name for example:
$(function() {
$(".add").click(function(){
//Save the link in a variable called element
var element = $(this);
//Find the id of the link that was clicked
var del_id = element.attr("dataid");
var outime = $(this).parents(".list").find(".outtime").val();
//Built a url to send
var info = 'id=' + del_id+ '&singout=' + outime;
$.ajax({
type: "POST",
url: "signOut.php",
data: info,
success: function(){}
});
// After success
$(this).parents(".list").animate({ backgroundColor: "#fbc7c7" }, "fast").animate({ opacity: "hide" }, "slow");
});
});
HTML/PHP:
<?php
$comments = runQuery($conn, "SELECT * FROM `civ_in_out` WHERE `out_time` = 'null'");
//print_r($comments) ;
if(!empty($comments)) {
foreach($comments as $k=>$v) {
?>
<div class="list">
<div class="form-group">
<div class="form-row">
<div class="col-md-3">
<input class="form-control" type="text" name="name[]" value="<?php echo $comments[$k]['name']; ?>" disabled>
</div>
<div class="col-md-3">
<input class="form-control" type="time" name="signIn[]" value="<?php echo $comments[$k]['in_time']; ?>" disabled>
</div>
<div class="col-md-3">
<input class="form-control outtime" id="outtime-<?=$k?>" type="time" name="singOut[]">
<input class="form-control" id="id-<?=$k?>" type="hidden" name="id[]" value="<?php echo $comments[$k]['id']; ?>">
</div>
<div class="col-md-3">
<a class="btn btn-primary btn-block add" dataid="<?php echo $comments[$k]['id']; ?>>Sign Out</a>
</div>
</div>
</div>
</div>
<?php
} }
?>
You can change $("#add").click(function() to $(document).on('click', '#add', function()
Related
I have a modal for entering user information. A user should be linked to a building. After user information has been entered and submit button has been clicked, I am preventing the default action and am overlaying/showing a building modal over the user modal.
Code for doing so follows.
(function($) {
$('#modalAddUser').modal('show');
$('#formAddUser').on('submit', function(e) {
e.preventDefault();
let name_user = $('input[name="name"]').val();
let address_user = $('input[name="address"]').val();
let city_user = $('input[name="city"]').val();
$.ajax({
url: './modals/modalConnectBuilding.php',
method: 'post',
data: {
"name_user": name_user,
"address_user": address_user,
"city_user": city_user
},
success: function() {
console.log(name_user);
console.log(address_user);
console.log(city_user);
}
});
$('#modalConnectBuilding').modal('show');
});
})(window.jQuery);
console.log() logs the input information correctly, however in 'modalConnectBuilding.php' the following does not work:
<?php
echo $_POST['name_user'];
echo $_POST['address_user'];
echo $_POST['city_user'];
?>
Producing the following errors:
Undefined index: name_user in
C:\laragon\www\modals\modalConnectBuilding.php
Undefined index: address_user in
C:\laragon\www\modals\modalConnectBuilding.php
Undefined index: city_user in
C:\laragon\www\modals\modalConnectBuilding.php
My intent is to do a classic 'form action="./php/processConnectBuilding.php" method="post"' but would need access to the three undefined variables as seen above. Adding users and buildings works in isolation but not when connected in this way. Any help would be greatly appreciated and if you need any more info, please ask. Thank you!
Code for the form (within the modal) I'm submitting follows (please note, default action is being suppressed by preventDefault() so action attribute is never "called", also the form for connecting a building is basically the same, but the action attribute is not suppressed):
<form role="form" id="formAddUser" action="./php/processAddUser.php" method="post">
<div class="form-group form-group-default required">
<label>Name</label>
<input type="text" name="name" class="form-control" required>
</div>
<div class="form-group form-group-default required">
<label>Address</label>
<input type="text" name="address" class="form-control" required>
</div>
<div class="form-group form-group-default required">
<label>City</label>
<input type="text" name="city" class="form-control" required>
</div>
<div style="margin-top: 25px">
<button type="submit" class="btn btn-primary btn-lg btn-block"><i class="fa fa-plus-circle"></i> Add</button>
</div>
</form>
<html>
<head>
<script src="https://code.jquery.com/jquery-2.2.0.min.js"></script>
</head>
<body>
<form role="form" id="formAddUser" action="" method="post">
<div class="form-group form-group-default required">
<label>Name</label>
<input type="text" id="name" name="name" class="form-control" required>
</div>
<div class="form-group form-group-default required">
<label>Address</label>
<input type="text" name="address" class="form-control" required>
</div>
<div class="form-group form-group-default required">
<label>City</label>
<input type="text" name="city" class="form-control" required>
</div>
<div style="margin-top: 25px">
<button type="submit" class="btn btn-primary btn-lg btn-block"><i class="fa fa-plus-circle"></i> Add</button>
</div>
</form>
</body>
</html>
<script>
$('#formAddUser').on('submit', function(e) {
e.preventDefault();
let name_user = $('input[name="name"]').val();
let address_user = $('input[name="address"]').val();
let city_user = $('input[name="city"]').val();
$.ajax({
url: 'tariffdetaildata.php',
method: 'post',
data: {
"name_user": name_user,
"address_user": address_user,
"city_user": city_user
},
success: function(data) {
alert(data)
}
});
});
</script>
tariffdetaildata.php
<?php
echo $_POST['name_user'];
echo $_POST['address_user'];
echo $_POST['city_user'];
Try this way I think you need to open the modal popup once you get the response back from the ajax.
(function($) {
$('#modalAddUser').modal('show');
$('#formAddUser').on('submit', function(e) {
e.preventDefault();
let name_user = $('input[name="name"]').val();
let address_user = $('input[name="address"]').val();
let city_user = $('input[name="city"]').val();
$.ajax({
url: './modals/modalConnectBuilding.php',
method: 'post',
data: {
"name_user": name_user,
"address_user": address_user,
"city_user": city_user
},
success: function() {
console.log(name_user);
console.log(address_user);
console.log(city_user);
$('#modalConnectBuilding').modal('show');
$("#modalConnectBuilding .modal-body #name_user").val( name_user);
$("#modalConnectBuilding .modal-body #address_user").val( address_user);
$("#modalConnectBuilding .modal-body #city_user").val( city_user);
}
});
});
})(window.jQuery);
I have the following form
<body>
<div class="container">
<div class="title pull-left"><img src="http://www.isfin.ro/images/institutul_de_studii_financiare_ISF.png" width="145px" height="80px" /></div>
<div class="title pull-right"><h1>Actualizare newsletter</h1></div>
</div>
<hr class="featurette-divider"></hr>
<div class="container">
<div class="col-sm-12">
GDPR text goes here
</div>
<div class="form-group">
<label for="email">Email:</label>
<input id="email" class="form-control" type="email" placeholder="Adresa Email">
</div>
<div class="form-group">
<label for="nume">Nume:</label>
<input id="nume" class="form-control" type="text" placeholder="Nume">
</div>
<p>Want to remain subscribed?</p>
<label class="radio-inline">
<input type="radio" name="optradio" value="yes">Yes
</label>
<label class="radio-inline">
<input type="radio" name="optradio" value="no">No
</label>
<br><br>
<button type="submit" id="submit" class="btn btn-default btn-block btn-primary">Trimite</button>
<div id="display"></div>
<script>
$(document).ready(function(){
$("#submit").click(function(){
var em = $("#email").val();
var sub = $("#nume").val();
var com = $("#comments").val();
var dataString = 'em1='+ em + '&sub1='+ sub + '&com1='+ com;
if(em==''||sub==''||com=='')
{
$("#display").html("<div class='alert alert-warning'>Please Fill All Fields.</div>");
}
else
{
$.ajax({
type: "POST",
url: "processor.php",
data: dataString,
cache: false,
success: function(result){
$("#display").html(result);
}
});
}
return false;
});
});
</script>
</div>
</body>
And this is the content of processor.php
<?php
include_once('config.php');
$email=mysqli_real_escape_string($con, $_POST['em1']);
$emailclean = filter_var($email, FILTER_SANITIZE_EMAIL, FILTER_FLAG_STRIP_HIGH);
$sub=mysqli_real_escape_string($con, $_POST['sub1']);
$subclean = filter_var($sub, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH);
//insert into database
mysqli_query($con,"INSERT INTO contact(`email`, `nume`)VALUES('$emailclean','$subclean')");
//send message back to AJAX
echo '<div class="alert alert-success">Preferintele au fost actualizate.</div>';
$con->close();
?>
How can I insert the content of the radio buttons Yes / No into a database field?
My database have the following structure id, email, nume, subscription_status, i need to insert the value from radio buttons into subscription_status (Yes or No value).
Thanks!
Get the value of selected checkbox:
var data = document.querySelector('input[name="optradio"]:checked').value;
Now add this value to your data string which you are sending via ajax:
var dataString = 'em1='+ em + '&sub1='+ sub + '&com1='+ com + '&radio=' + data;
And get the value on PHP/server side:
$radio_value = $_POST['radio'];
I'm trying to submit the form in the same page without refresh the page.
my form:
<?php
if(isset($_POST['transfer'])){
$amount = $_POST['amount'] ? $_POST['amount'] : '';
$from_c = $_POST['from_c'] ? $_POST['from_c'] :'';
$to_c = $_POST['to_c'] ? $_POST['to_c'] : '';
}
?>
<form class="form-inline" method="post" action="convert.php" onsubmit = 'return false;' id = "frmData">
<div class="md-form form-group col-sm-3">
<div class="input-group col-sm-12">
<input type="number" value="1" min="0" step="0.01" data-number-to-fixed="2" data-number-stepfactor="100" class="form-control" name="amount">
<span class="input-group-addon" id="natCurrency" style="margin-top: 10%;margin-left: -5;margin-right: 15%;"></span>
</div>
</div>
<div class="">
<label for="from_c">from currency</label>
<select id="natSelect" onchange="let csymbol = $(this).find(':selected').data('symbol');$('#natCurrency').text(csymbol) " name="from_c" class="mdb-select colorful-select dropdown-primary" style="width:200px;" placeholder="select currency" >
<?php foreach ($black_a as $name => $black_p) {
?>
<option value="<?php echo $black_p['name'];?>" data-symbol="<?php echo $black_p['symbol_native']; ?>"><?php echo $black_p['name'];?></option>
<?php } ?>
</select>
</div>
<div class="">
<label for="to_c">to currency</label>
<select class="mdb-select colorful-select dropdown-primary" name="to_c" style="width:200px;" >
<?php foreach ($black_a as $name => $black_p) {
?>
<option value="<?php echo $black_p['name'];?>"><?php echo $black_p['name'];?></option>
<?php } ?>
</select>
</div>
<input name="transfer" value="convert" class="btn btn-elegant" style="margin-top:3%;" id = "ha" />
</form>
And I have this PHP code when the form is submitted:
<?php
if(isset($from_c) &&$from_c ==$to_c && isset($to_c) && $to_c == $from_c){
echo "
<div id='less' class='well'>
<div dir='RTL'>
<ul class='text-right'>
<li><strong>resultل</li>
</ul>
<div class='col-md-4'>
<div class='msg msg-success msg-success-text'> <span class='glyphicon glyphicon glyphicon-ok'></span> Error !</div>
</div>
";
}
?>
I tried using AJAX, the page is still refreshing after clicking submit:
$('#ha').on('click', function (e) {
e.preventDefault(); //prevent to reload the page
$.ajax({
type: 'POST', //hide url
url: 'convert.php', //your form validation url
data: $('#frmData').serialize(), //USE THE ID WE SET IN THE FORM
success: function (response) {
$(".mydiv").append(response);
}
});
});
.mydiv:
<div class='mydiv'>
<div dir='RTL'>
<ul class='text-right'>
<li><strong>result</li>
</ul>
<div class='col-md-4'>
<div class='msg msg-success msg-success-text'> <span class='glyphicon glyphicon glyphicon-ok'></span> $amount</div>
</div>
I also tried to using iframe but when clicking the submit button nothing happens.
How can I make this works and displaying the message I have in the if statement in my second PHP code?
This will work If this is your submit button
<input type="submit" name="transfer" value="convert" class="btn btn-elegant" style="margin-top:3%;" />
Change it to
<input name="transfer" value="convert" class="btn btn-elegant" style="margin-top:3%;" id = "ha" /> //ADD AN ID TO SPECIFY THE ON CLICK TRIGGER
Then your form
<form class="form-inline" method="post" action="convert.php" >
Change it to
<form class="form-inline" method="post" action="convert.php" onsubmit = 'return false;' id = "frmData"> // ADD AN ID TO YOUR FORM
Then minor adjustment to your script
$('#ha').on('click', function (e) {
e.preventDefault(); //prevent to reload the page
$.ajax({
type: 'POST', //hide url
url: 'convert.php', //your form validation url
data: $('#frmData').serialize(), //USE THE ID WE SET IN THE FORM
success: function (response) {
$(".yourDiv").append(response);
}
});
});
to achieve this you have to make changes in your code first change your form part like this
<form class="form-inline" method="post" action="convert.php" onsubmit = 'return false;' id = "frmData">
change your submit button like this
<input name="transfer" value="convert" class="btn btn-elegant" style="margin-top:3%;" id = "ha" />
then in your ajax function add e.preventDefault(); in first line .
I have to submit a form with some fields, like multiple checkboxes selection and some hidden input fields via ajax and replace html content with response. finally i go with javascript/ajax...but where i was wrong?
<?php include( 'session.php');
$userid=$_SESSION[ 'Userid'];
include( 'connection.php');
?>
<head>
<script>
function myFunction() {
var soi = document.getElementById("sweaterownerid").value;
var osp = document.getElementById("osweaterpic").value;
var osi = document.getElementById("osweaterid").value;
var value = [];
$("input[name*='" + sweater+ "']").each(function () {
// Get all checked checboxes in an array
if (jQuery(this).is(":checked")) {
value.push($(this).val());
}
});
var dataString = 'soi1=' + soi + '&osp1=' + osp + '&osi1=' + osi + '&value1=' + value;
if (soi1 == '' || osp1 == '' || osi1 == '' || value1 == '') {
alert("Please Fill All Fields");
} else {
// AJAX code to submit form.
$.ajax({
type: "POST",
url: "Usercloset1.php",
data: dataString,
cache: false,
success: function(response) {
$('#mydiv').replaceWith(response);
}
});
}
return false;
}
</script>
</head>
<div id="mydiv">
<div class="padding-top">
<div class="col-lg-3 col-md-3 col-sm-6 col-xs-12 ">
<div class="shop_item" style="width:100%;">
<form id="myForm">
<?php
$sweaterid=$_GET['d'];
$sownerid=$_GET['e'];
$opic=$_GET['f'];
$query1="select * from `usersweater` where `Sweaterid`='$sweaterid'";
$result1=mysql_query($query1);
$row1=mysql_fetch_assoc($result1);
$sweaternikname=$row1['SNickname'];
?>
<div>
<ul class="sweaters">
<li> <h4><?php echo $sweaternikname; ?></h4> <img src="upload/<?php echo $opic; ?>"> </li>
</ul>
<ul class="sweater1">
<?php
$query="select * from `usersweater` where `Userid`='$userid' && `Swap`='0' ";
$result = mysql_query($query);
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)){
$sid = $line[Sweaterid];
$img = $line[Sweaterpic];
$nikname = $line[SNickname];
$size = $line[Size];
?>
<li> <h4><?php echo $nikname; ?><input type="checkbox" name="sweater[]" value="<?php echo $sid; ?>" /></h4> <img src="upload/<?php echo $img; ?>"> </li>
<?php } ?>
</ul>
</div>
<input type="hidden" name="sweaterownerid" value="<?php echo $sownerid; ?>">
<input type="hidden" name="osweaterpic" value="<?php echo $opic; ?>">
<input type="hidden" name="osweaterid" value="<?php echo $sweaterid; ?>">
<input type="submit" name="next" onclick="myFunction()" value="NEXT" class="btn woo_btn btn-primary" style="margin-left: 30px;">
<input type="button" name="cancel" value="CANCEL" class="btn woo_btn btn-primary">
</form>
</div>
</div>
<div class="clearfix"></div>
<hr>
</div>
</div>
I want to pass the selected option to another page, which I do now using form action. But I want it dynamically without reloading page. I am new to ajax/javascript.
Second thing is, how can I handle the response, where submitting this form I want to replace first page content with the reponse that we get using ajax. This means replace all html content with other page's html content. I atteched the file which I want in response after submit.
<div class="padding-top">
<div class="col-lg-3 col-md-3 col-sm-6 col-xs-12 ">
<div class="shop_item" style="width:100%;">
<div style="text-align:center;">
<h4>Are you sure you want to swap?</h4>
</div>
<form action="Usercloset2.php" method="post">
<?php
include('session.php');
include('connection.php');
foreach ($_POST['value1'] as $sid){
$query1="select * from `usersweater` where `Sweaterid`='$sid'";
$result1=mysql_query($query1);
$row1=mysql_fetch_assoc($result1);
$sweaternikname=$row1['SNickname'];
$sweaterpic=$row1['Sweaterpic'];
?>
<div style=" ">
<ul class="sweaters">
<li> <h4><?php echo $sweaternikname; ?></h4> <img src="upload/<?php echo $sweaterpic; ?>"> </li>
</ul>
</div>
<!-------requester's own sweater details--------------->
<input type="hidden" name="sid[]" value="<?php echo $sid;?>">
<input type="hidden" name="snikname[]" value="<?php echo $sweaternikname;?>">
<input type="hidden" name="spic[]" value="<?php echo $sweaterpic;?>">
<?php } ?>
<!-------requester's show intrest that sweater details--------------->
<?php
$sownerid=$_POST['soi1'];
$opic=$_POST['osp1'];
$sweaterid=$_POST['osi1'];
?>
<input type="hidden" name="sweaterownerid" value="<?php echo $sownerid;?>">
<input type="hidden" name="osweaterpic" value="<?php echo $opic;?>">
<input type="hidden" name="osweaterid" value="<?php echo $sweaterid;?>">
<div style="float:right; margin-right:10px;">
<input type="submit" name="next" value="NEXT" class="btn woo_btn btn-primary">
<input type="button" name="cancel" value="CANCEL" class="btn woo_btn btn-primary">
</div>
</form>
</div>
</div>
<div class="clearfix"></div>
<hr>
</div>
you can use in your Ajax like this:
var form = $('#your_form_id');
var formAction = $('#your_form_id').attr('action');
/* Get input values from form */
values = form.serializeArray();
/* Because serializeArray() ignores unset checkboxes and radio buttons: */
values = values.concat(
$('#your_form_id input[type=checkbox]:not(:checked)').map(
function() {
return {
"name": this.name,
"value": this.value
}
}).get()
);
$.ajax({
'ajax code here'
});
or you can check https://api.jquery.com/serialize/
You can achive it though this.
jQuery(document).ready(function($){
$("#your_button_id").on('click', function(e){
e.preventDefault();
$("#your_form_id") .submit();
})
})
Ajax
$("#your_form_id").on('submit', function(e) {
e.preventDefault();
$.post('URL_HERE', $(this).serialize(), function(response) {
console.log(response)
});
});
I have 2 forms on a page with structures
<div id="tabs-7">
<form action="/admin/languages" id="1" class="mainForm" method="POST">
<fieldset>
<div class="widget">
<input type="hidden" maxlength="40"class="autoF" name="base" id="base" value="<?php echo base_url(); ?>" />
<input type="hidden" maxlength="40"class="autoF" id="lang_id" name="lang_id" value="1" />
<div class="rowElem">
<label>Calender</label>
<div class="rowElem noborder" >
<label>Date:</label>
<div class="formLeft">
<input type="text" name="date" class="datepicker date" value="<?php echo isset($data['1']['date']['text']) ? $data['1']['date']['text'] : ""; ?>" />
</div>
</div>
<label> Note:</label>
<div class="formLeft">
<?php
if (!empty($data['1']['calender_contents'])) {
$text = preg_replace('/\s+/', ' ', $data['1']['calender_contents']['text']);
}
?>
<textarea name="calender_contents" class="auto limit calender_contents" style="min-width: 600px;max-width: 600px;min-height:80px;max-height: 80px;"><?php echo isset($data['1']['calender_contents']['text']) ? $text : ""; ?></textarea>
</div>
<div class="rowElem "><input type="button" value="Add Note" class="blueBtn left addnote"></div>
</div>
<div class="rowElem "><input type="submit" value="Save" class="greenBtn right"></div>
</div>
</fieldset>
</form>
</div>
<div id="tabs-8">
<form action="/admin/languages" id="2" class="mainForm" method="POST">
<fieldset>
<div class="widget">
<input type="hidden" maxlength="40"class="autoF" name="base" id="base" value="<?php echo base_url(); ?>" />
<input type="hidden" maxlength="40"class="autoF" id="lang_id" name="lang_id" value="2" />
<div class="rowElem">
<label>Calender</label>
<div class="rowElem noborder" >
<label>Date:</label>
<div class="formLeft">
<input type="text" name="date" class="datepicker date" value="<?php echo isset($data['2']['date']['text']) ? $data['2']['date']['text'] : ""; ?>" />
</div>
</div>
<label> Note:</label>
<div class="formLeft">
<?php
if (!empty($data['2']['calender_contents'])) {
$text = preg_replace('/\s+/', ' ', $data['1']['calender_contents']['text']);
}
?>
<textarea name="calender_contents" class="auto limit calender_contents" style="min-width: 600px;max-width: 600px;min-height:80px;max-height: 80px;"><?php echo isset($data['2']['calender_contents']['text']) ? $text : ""; ?></textarea>
</div>
<div class="rowElem "><input type="button" value="Add Note" class="blueBtn left addnote"></div>
</div>
<div class="rowElem "><input type="submit" value="Save" class="greenBtn right"></div>
</div>
</fieldset>
</form>
</div>
and javascript :
$(".datepicker").datepicker({
defaultDate: +7,
autoSize: true,
appendText: '(yyyy-mm-dd)',
dateFormat: 'yy-mm-dd',
onClose: function(dateText, inst) {
var form = $(this).closest("form");
var formID = $(form).attr("id");
console.log(formID);
if(formID == "1"){
formID = 1;
}
else{
formID = 2;
}
var lang_id = formID;
var date = $(".date").val();
console.log(lang_id);
console.log(date);
$.ajax({
type: 'POST',
url: "/admin/getnote",
dataType: "json",
data: {"date": date, "lang_id": lang_id},
success: function(data) {
console.log(data.arr[0]);
if(data.arr[0] != undefined){
$('.calender_contents').val(data.arr[0].note);
$('.date').val(data.arr[0].date);
}
else {
$('.calender_contents').val("");
}
}
});
}
});
I am able to get the value from the database in the first tab that is tab 7 fine and value
but when use the date picker in the second form to its value also gets displayed in the first table so was looking for some advise as how i can combine $(this).closest("form"); with these fields
$('.calender_contents').val(data.arr[0].note);
$('.date').val(data.arr[0].date);
so that i could get value in the specific form field . Thank you.
You select #calendar_contents. If you use the same "id" for 2 elements, first you're doing it wrong (an id must be unique), then jQuery will only return you the first element that has the requested id.
Try using a class and "locate" the tab you're using.
You can't have html elements on the same page that have the same id, even if they are in different forms. The id attribute must be unique on the whole page