Hi,
I'm currently working on a website for my dad that has dynamic fields (hit a button and an html template gets displayed). You can see the template in use here...
http://hbndev.com/ipad/index.php?option=com_content&view=article&id=5&Itemid=6
As you can see it works, perfectly. EXCEPT for when you add a field it drops to below the form. I want it to drop right below the first field.
IE. If you hit the plus button on monday, another monday pops below the first monday field.
Here is the javascript:
<script type="text/javascript">
var ct = 1;
function monday_field()
{
ct++;
var div1 = document.createElement('div');
div1.id = ct;
// link to delete extended form elements
var delLink = '';
div1.innerHTML = document.getElementById('mondayfield').innerHTML + delLink;
document.getElementById('newlink').appendChild(div1);
}
function tuesday_field()
{
ct++;
var div1 = document.createElement('div');
div1.id = ct;
// link to delete extended form elements
var delLink = '';
div1.innerHTML = document.getElementById('tuesdayfield').innerHTML + delLink;
document.getElementById('newlink').appendChild(div1);
}
function wednesday_field()
{
ct++;
var div1 = document.createElement('div');
div1.id = ct;
// link to delete extended form elements
var delLink = '';
div1.innerHTML = document.getElementById('wednesdayfield').innerHTML + delLink;
document.getElementById('newlink').appendChild(div1);
}
function thursday_field()
{
ct++;
var div1 = document.createElement('div');
div1.id = ct;
// link to delete extended form elements
var delLink = '';
div1.innerHTML = document.getElementById('thursdayfield').innerHTML + delLink;
document.getElementById('newlink').appendChild(div1);
}
function friday_field()
{
ct++;
var div1 = document.createElement('div');
div1.id = ct;
// link to delete extended form elements
var delLink = '';
div1.innerHTML = document.getElementById('fridayfield').innerHTML + delLink;
document.getElementById('newlink').appendChild(div1);
}
function saturday_field()
{
ct++;
var div1 = document.createElement('div');
div1.id = ct;
// link to delete extended form elements
var delLink = '';
div1.innerHTML = document.getElementById('saturdayfield').innerHTML + delLink;
document.getElementById('newlink').appendChild(div1);
}
function sunday_field()
{
ct++;
var div1 = document.createElement('div');
div1.id = ct;
// link to delete extended form elements
var delLink = '';
div1.innerHTML = document.getElementById('sundayfield').innerHTML + delLink;
document.getElementById('newlink').appendChild(div1);
}
function delIt(eleId)
{
d = document;
var ele = d.getElementById(eleId);
var parentEle = d.getElementById('newlink');
parentEle.removeChild(ele);
}
</script>
Here is the HTML:
<form action="timecards.php" method="post" name="timecard">
<div id="newlink">
<div class="form">
Employee:
<br>
<select class="employee" name="employeetype" size="1" onChange="redirect(this.options.selectedIndex)">
<option>Lath Employees</option>
<option>Plaster Employees</option>
<option>Scaffold Employees</option>
</select>
<select name="employee" size="1">
<option>Employee #</option>
</select>
<?php include 'timecardfiles/timecardemployees.html'; ?>
<input type="text" name="employeetype" value="Employee (If Missing)" onfocus="this.value=''">
<br><br>
<!-- Monday Fields -->
Week Ending Sunday:
<br>
<input name="weekending" value="Month / Day / Year" onfocus="this.value=''" type="number">
<br><br>
Monday:
<select class="mondayjobnumber" name="mondayjobnumber[]" size="1">
<option selected="selected">Job #</option>
<?php include 'timecardfiles/timecardjobs.html'; ?>
</select>
<select class="mondaycostcode" name="mondaycostcode[]" size="1">
<option selected="selected">Cost Code #</option>
<?php include 'timecardfiles/timecardcostcodes.html'; ?>
</select>
<select class="mondayphase" name="mondayphase[]" size="1">
<option selected="selected">Phase #</option>
<?php include 'timecardfiles/timecardphases.html'; ?>
</select>
<select class="mondayhours" name="mondayhours[]" size="1">
<option selected="selected">Hours</option>
<?php include 'timecardfiles/timecardhours.html'; ?>
</select>
<a class="addjob" href="javascript:monday_field()" mce_href="javascript:monday_field()">+</a>
<br><br>
<!-- Tuesday Fields -->
Tuesday:
<select class="tuesdayjobnumber" name="tuesdayjobnumber[]" size="1">
<option selected="selected">Job #</option>
<?php include 'timecardfiles/timecardjobs.html'; ?>
</select>
<select class="tuesdaycostcode" name="tuesdaycostcode[]" size="1">
<option selected="selected">Cost Code #</option>
<?php include 'timecardfiles/timecardcostcodes.html'; ?>
</select>
<select class="tuesdayphase" name="tuesdayphase[]" size="1">
<option selected="selected">Phase #</option>
<?php include 'timecardfiles/timecardphases.html'; ?>
</select>
<select class="tuesdayhours" name="tuesdayhours[]" size="1">
<option selected="selected">Hours</option>
<?php include 'timecardfiles/timecardhours.html'; ?>
</select>
<a class="addjob" href="javascript:tuesday_field()" mce_href="javascript:tuesday_field()">+</a>
<br><br>
<!-- Wednesday Fields -->
Wednesday:
<select class="wednesdayjobnumber" name="wednesdayjobnumber[]" size="1">
<option selected="selected">Job #</option>
<?php include 'timecardfiles/timecardjobs.html'; ?>
</select>
<select class="wednesdaycostcode" name="wednesdaycostcode[]" size="1">
<option selected="selected">Cost Code #</option>
<?php include 'timecardfiles/timecardcostcodes.html'; ?>
</select>
<select class="wednesdayphase" name="wednesdayphase[]" size="1">
<option selected="selected">Phase #</option>
<?php include 'timecardfiles/timecardphases.html'; ?>
</select>
<select class="wednesdayhours" name="wednesdayhours[]" size="1">
<option selected="selected">Hours</option>
<?php include 'timecardfiles/timecardhours.html'; ?>
</select>
<a class="addjob" href="javascript:wednesday_field()" mce_href="javascript:wednesday_field()">+</a>
<br><br>
<!-- Thursday Fields -->
Thursday:
<select class="thursdayjobnumber" name="thursdayjobnumber[]" size="1">
<option selected="selected">Job #</option>
<?php include 'timecardfiles/timecardjobs.html'; ?>
</select>
<select class="thursdaycostcode" name="thursdaycostcode[]" size="1">
<option selected="selected">Cost Code #</option>
<?php include 'timecardfiles/timecardcostcodes.html'; ?>
</select>
<select class="thursdayphase" name="thursdayphase[]" size="1">
<option selected="selected">Phase #</option>
<?php include 'timecardfiles/timecardphases.html'; ?>
</select>
<select class="thursdayhours" name="thursdayhours[]" size="1">
<option selected="selected">Hours</option>
<?php include 'timecardfiles/timecardhours.html'; ?>
</select>
<a class="addjob" href="javascript:thursday_field()" mce_href="javascript:thursday_field()">+</a>
<br><br>
<!-- Friday Fields -->
Friday:
<select class="fridayjobnumber" name="fridayjobnumber[]" size="1">
<option selected="selected">Job #</option>
<?php include 'timecardfiles/timecardjobs.html'; ?>
</select>
<select class="fridaycostcode" name="fridaycostcode[]" size="1">
<option selected="selected">Cost Code #</option>
<?php include 'timecardfiles/timecardcostcodes.html'; ?>
</select>
<select class="fridayphase" name="fridayphase[]" size="1">
<option selected="selected">Phase #</option>
<?php include 'timecardfiles/timecardphases.html'; ?>
</select>
<select class="fridayhours" name="fridayhours[]" size="1">
<option selected="selected">Hours</option>
<?php include 'timecardfiles/timecardhours.html'; ?>
</select>
<a class="addjob" href="javascript:friday_field()" mce_href="javascript:friday_field()">+</a>
<br><br>
<!-- Saturday Fields -->
Saturday:
<select class="saturdayjobnumber" name="saturdayjobnumber[]" size="1">
<option selected="selected">Job #</option>
<?php include 'timecardfiles/timecardjobs.html'; ?>
</select>
<select class="saturdaycostcode" name="saturdaycostcode[]" size="1">
<option selected="selected">Cost Code #</option>
<?php include 'timecardfiles/timecardcostcodes.html'; ?>
</select>
<select class="saturdayphase" name="saturdayphase[]" size="1">
<option selected="selected">Phase #</option>
<?php include 'timecardfiles/timecardphases.html'; ?>
</select>
<select class="saturdayhours" name="saturdayhours[]" size="1">
<option selected="selected">Hours</option>
<?php include 'timecardfiles/timecardhours.html'; ?>
</select>
<a class="addjob" href="javascript:saturday_field()" mce_href="javascript:saturday_field()">+</a>
<br><br>
<!-- Sunday Fields -->
Sunday:
<select class="sundayjobnumber" name="sundayjobnumber[]" size="1">
<option selected="selected">Job #</option>
<?php include 'timecardfiles/timecardjobs.html'; ?>
</select>
<select class="sundaycostcode" name="sundaycostcode[]" size="1">
<option selected="selected">Cost Code #</option>
<?php include 'timecardfiles/timecardcostcodes.html'; ?>
</select>
<select class="sundayphase" name="sundayphase[]" size="1">
<option selected="selected">Phase #</option>
<?php include 'timecardfiles/timecardphases.html'; ?>
</select>
<select class="sundayhours" name="sundayhours[]" size="1">
<option selected="selected">Hours</option>
<?php include 'timecardfiles/timecardhours.html'; ?>
</select>
<a class="addjob" href="javascript:tuesday_field()" mce_href="javascript:tuesday_field()">+</a>
<br><br>
<?php include 'timecardfiles/timecardtemplates.html'; ?>
</div>
</div>
<!-- Submit / Reset Form -->
<input class="button" name="submit1" value="Email" type="submit">
<input class="button" name="reset1" value="Reset" type="reset">
</form>
And here is the HTML for the form templates...
<!-- Monday Template -->
<div id="mondayfield" style="display: none;" mce_style="display:none">
Monday:
<select class="mondayjobnumber" name="mondayjobnumber[]" size="1">
<option selected="selected">Job #</option>
<?php include 'timecardjobs.html'; ?>
</select>
<select class="mondaycostcode" name="mondaycostcode[]" size="1">
<option selected="selected">Cost Code #</option>
<?php include 'timecardcostcodes.html'; ?>
</select>
<select class="mondayphase" name="mondayphase[]" size="1">
<option selected="selected">Phase #</option>
<?php include 'timecardphases.html'; ?>
</select>
<select class="mondayhours" name="mondayhours[]" size="1">
<option selected="selected">Hours</option>
<?php include 'timecardhours.html'; ?>
</select>
<a class="addjob" href="javascript:monday_field()" mce_href="javascript:monday_field()">+</a>
<br><br>
</div>
<!-- Tuesday Template -->
<div id="tuesdayfield" style="display: none;" mce_style="display:none">
Tuesday:
<select class="tuesdayjobnumber" name="tuesdayjobnumber[]" size="1">
<option selected="selected">Job #</option>
<?php include 'timecardjobs.html'; ?>
</select>
<select class="tuesdaycostcode" name="tuesdaycostcode[]" size="1">
<option selected="selected">Cost Code #</option>
<?php include 'timecardcostcodes.html'; ?>
</select>
<select class="tuesdayphase" name="tuesdayphase[]" size="1">
<option selected="selected">Phase #</option>
<?php include 'timecardphases.html'; ?>
</select>
<select class="tuesdayhours" name="tuesdayhours[]" size="1">
<option selected="selected">Hours</option>
<?php include 'timecardhours.html'; ?>
</select>
<a class="addjob" href="javascript:tuesday_field()" mce_href="javascript:tuesday_field()">+</a>
<br><br>
</div>
<!-- Wednesday Template -->
<div id="wednesdayfield" style="display: none;" mce_style="display:none">
Wednesday:
<select class="wednesdayjobnumber" name="wednesdayjobnumber[]" size="1">
<option selected="selected">Job #</option>
<?php include 'timecardjobs.html'; ?>
</select>
<select class="wednesdaycostcode" name="wednesdaycostcode[]" size="1">
<option selected="selected">Cost Code #</option>
<?php include 'timecardcostcodes.html'; ?>
</select>
<select class="wednesdayphase" name="wednesdayphase[]" size="1">
<option selected="selected">Phase #</option>
<?php include 'timecardphases.html'; ?>
</select>
<select class="wednesdayhours" name="wednesdayhours[]" size="1">
<option selected="selected">Hours</option>
<?php include 'timecardhours.html'; ?>
</select>
<a class="addjob" href="javascript:wednesday_field()" mce_href="javascript:wednesday_field()">+</a>
<br><br>
</div>
<!-- Thursday Template -->
<div id="thursdayfield" style="display: none;" mce_style="display:none">
Thursday:
<select class="thursdayjobnumber" name="thursdayjobnumber[]" size="1">
<option selected="selected">Job #</option>
<?php include 'timecardjobs.html'; ?>
</select>
<select class="thursdaycostcode" name="thursdaycostcode[]" size="1">
<option selected="selected">Cost Code #</option>
<?php include 'timecardcostcodes.html'; ?>
</select>
<select class="thursdayphase" name="thursdayphase[]" size="1">
<option selected="selected">Phase #</option>
<?php include 'timecardphases.html'; ?>
</select>
<select class="thursdayhours" name="thursdayhours[]" size="1">
<option selected="selected">Hours</option>
<?php include 'timecardhours.html'; ?>
</select>
<a class="addjob" href="javascript:thursday_field()" mce_href="javascript:thursday_field()">+</a>
<br><br>
</div>
<!-- Friday Template -->
<div id="fridayfield" style="display: none;" mce_style="display:none">
<div class="form">
Friday:
<select class="fridayjobnumber" name="fridayjobnumber[]" size="1">
<option selected="selected">Job #</option>
<?php include 'timecardjobs.html'; ?>
</select>
<select class="fridaycostcode" name="fridaycostcode[]" size="1">
<option selected="selected">Cost Code #</option>
<?php include 'timecardcostcodes.html'; ?>
</select>
<select class="fridayphase" name="fridayphase[]" size="1">
<option selected="selected">Phase #</option>
<?php include 'timecardphases.html'; ?>
</select>
<select class="fridayhours" name="fridayhours[]" size="1">
<option selected="selected">Hours</option>
<?php include 'timecardhours.html'; ?>
</select>
<a class="addjob" href="javascript:friday_field()" mce_href="javascript:friday_field()">+</a>
<br><br>
</div>
<!-- Saturday Template -->
<div id="saturdayfield" style="display: none;" mce_style="display:none">
Saturday:
<select class="saturdayjobnumber" name="saturdayjobnumber[]" size="1">
<option selected="selected">Job #</option>
<?php include 'timecardjobs.html'; ?>
</select>
<select class="saturdaycostcode" name="saturdaycostcode[]" size="1">
<option selected="selected">Cost Code #</option>
<?php include 'timecardcostcodes.html'; ?>
</select>
<select class="saturdayphase" name="saturdayphase[]" size="1">
<option selected="selected">Phase #</option>
<?php include 'timecardphases.html'; ?>
</select>
<select class="saturdayhours" name="saturdayhours[]" size="1">
<option selected="selected">Hours</option>
<?php include 'timecardhours.html'; ?>
</select>
<a class="addjob" href="javascript:saturday_field()" mce_href="javascript:saturday_field()">+</a>
<br><br>
</div>
<!-- Sunday Template -->
<div id="sundayfield" style="display: none;" mce_style="display:none">
Sunday:
<select class="sundayjobnumber" name="sundayjobnumber[]" size="1">
<option selected="selected">Job #</option>
<?php include 'timecardjobs.html'; ?>
</select>
<select class="sundaycostcode" name="sundaycostcode[]" size="1">
<option selected="selected">Cost Code #</option>
<?php include 'timecardcostcodes.html'; ?>
</select>
<select class="sundayphase" name="sundayphase[]" size="1">
<option selected="selected">Phase #</option>
<?php include 'timecardphases.html'; ?>
</select>
<select class="sundayhours" name="sundayhours[]" size="1">
<option selected="selected">Hours</option>
<?php include 'timecardhours.html'; ?>
</select>
<a class="addjob" href="javascript:sunday_field()" mce_href="javascript:sunday_field()">+</a>
<br><br>
</div>
The includes are just options for the drop downs for easy editing so don't worry about that.
Thanks for any help :).