JavaScript and client side scripting.
Moderator: General Moderators
Grandong
Forum Commoner
Posts: 65 Joined: Thu Jul 03, 2014 12:35 pm
Location: Indonesian
Contact:
Post
by Grandong » Sat Jul 19, 2014 11:10 am
i have form with multiple datepicker
and id using loop
Include
Code: Select all
<link href="<?php echo base_url();?>assets/ws/jquery-ui.css" type="text/css" rel="stylesheet" />
<script src="<?php echo base_url();?>assets/ws/jquery-1.9.1.js"></script>
<script src="<?php echo base_url();?>assets/ws/jquery-ui.js"></script>
and this my code :
Code: Select all
<div class="form-group">
<label><?= $json_results['required']['birthdatea'.$i]["FieldText"]; ?></label>
<div class="input-group">
<span class="input-group-addon">
<i class="fa fa-calendar"></i>
</span>
<input type="text" id="birthdatea<?= $i; ?>" class="form-control" name="birthdatea[]" placeholder="">
<script type="text/javascript">
var s = $.noConflict();
s(document).ready(function(){
s("#birthdatea<?= $i; ?>").datepicker({
dateFormat: "yy-mm-dd",
changeMonth: true,
autoSize: true
});
});
</script>
</div>
</div>
id
birthdatea1 work, but
birthdatea2 datepicker not work, please help me
Newbie The Passion for Learning
Christopher
Site Administrator
Posts: 13596 Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US
Post
by Christopher » Mon Jul 21, 2014 9:10 am
Grandong wrote: id birthdatea1 work, but birthdatea2 datepicker not work, please help me
HOW is is not working?
A wild guess is that it is working but sending both dates in the same form var. Maybe:
Code: Select all
<input type="text" id="birthdatea<?= $i; ?>" class="form-control" name="birthdatea<?= $i; ?>[]" placeholder="">
(#10850)
thinsoldier
Forum Contributor
Posts: 367 Joined: Fri Jul 20, 2007 11:29 am
Contact:
Post
by thinsoldier » Thu Aug 21, 2014 6:08 pm
Is your datepicker a jQuery plugin?
Will all your datepickers use the same options?
If yes to both questions it's very likely you can simple apply the datepicker to all date fields with a single call and don't need to include it within the php loop and don't need to give each date field a unique id.
Code: Select all
<input type="text" class="form-control jq-datepicker" name="birthdatea[]" placeholder="">
<input type="text" class="form-control jq-datepicker" name="birthdatea[]" placeholder="">
<input type="text" class="form-control jq-datepicker" name="birthdatea[]" placeholder="">
<input type="text" class="form-control jq-datepicker" name="birthdatea[]" placeholder="">
Code: Select all
s(document).ready(function( $ ){
$('.jq-datepicker').datepicker({
dateFormat: "yy-mm-dd",
changeMonth: true,
autoSize: true
});
})
Warning: I have no idea what I'm talking about.