Okay, So I am sure this can’t be that complicated yet I am struggling so any help is greatly appreciated.
I am building a dynamic form, where the user can add as many inputs as they need. I have the html side of things working just fine, but for every input they create I need to create a corresponding javascript function that is tied to that specific input. (It’s a Calendar selector), and each input needs its own unique trigger.
I tried appending the code straight with the javascript but that ends in a mess, I figure tahts due to the javascript tags....
<td class="value"><input name="<?php echo $_htmlName; ?>[devices_{{id}}][activationdate]" id="<?php echo $_htmlName; ?>[devices_{{id}}][activationdate]" value="" type="text" class=" input-text" style="width:110px !important;"> <img src=" /images/grid-cal.gif" alt="" class="v-middle" id="<?php echo $_htmlName; ?>[devices_{{id}}][activationdate]_trig" title="Select Date" style=""><script type="text/javascript">Calendar.setup({inputField: "<?php echo $_htmlName; ?>[devices_{{id}}][activationdate]", ifFormat: "%m/%e/%Y %I:%M %p", showsTime: true, button: "<?php echo $_htmlName; ?>[devices_{{id}}][activationdate]_trig", align: "Bl", singleClick : true });</script></td>
var _form_html_row = '<td class="value"><input name="<?php echo $_htmlName; ?>[devices_{{id}}][activationdate]" id="<?php echo $_htmlName; ?>[devices_{{id}}][activationdate]" value="" type="text" class=" input-text" style="width:110px !important;"> <img src=" /images/grid-cal.gif" alt="" class="v-middle" id="<?php echo $_htmlName; ?>[devices_{{id}}][activationdate]_trig" title="Select Date" style=""><script type="text/javascript">Calendar.setup({inputField: "<?php echo $_htmlName; ?>[devices_{{id}}][activationdate]", ifFormat: "%m/%e/%Y %I:%M %p", showsTime: true, button: "<?php echo $_htmlName; ?>[devices_{{id}}][activationdate]_trig", align: "Bl", singleClick : true });</script></td>'
var _device_counter = <?php echo $_counter?>;
$('add_new_devices_button').observe('click', function(){
$('attribute-options-table').insert(_form_html_row.replace(/\{\{id\}\}/ig, _ device _counter));
_ device _counter++;
});
Please excuse the compressed html / javascript, side question is there any way I can do this without dropping all the html into a single line?
Aucun commentaire:
Enregistrer un commentaire