php - fetching value from multiple forms and displaying in the appropriate field based on form id -
i have 2 forms on page 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 able value database in first tab tab 7 fine , value when use date picker in second form value gets displayed in first table looking advise how can combine $(this).closest("form");
these fields
$('.calender_contents').val(data.arr[0].note); $('.date').val(data.arr[0].date);
so value in specific form field . thank you.
you select #calendar_contents. if use same "id" 2 elements, first you're doing wrong (an id must unique), jquery return first element has requested id.
try using class , "locate" tab you're using.
Comments
Post a Comment