I’m new to javascript and I cannot work this out despite looking around a lot and trying to work through all the form functions etc that Javascript has.
I have a script (below) that works fine however i want to keep the data entered by the user so that when they add another session it just adds another set of times to the bottom, without loosing their already entered data.
If you know how to do this please let me know!
Thankyou sooo much for any help!
[CODE]<html>
<head>
<title>Dynamic Schedule Demonstration</title>
<script type=”text/javascript”>
//initialise the form variables
// letter multiples that applies
var oc_letter = ‘a’;
var yes_letter = ‘a’;
var no_letter = ‘b’;
var repititions_of_fields = 0;
//the string that is to be repeated
var core_string = “”;
core_string += “<td rowspan=’2′>For all days</td>” ;
core_string += “<td>Open</td><td align = ‘left’><small>  HH    MM<br><input name=’open_hours_a’ type=’text’ size=’1′>:<input name=’open_minutes_a’ type=’text’ size=’1′><input name=’open_ap_a’ type=’radio’ value=’AM’>AM<input name=’open_ap_a’ type=’radio’ value=’PM’>PM</small></td></tr> ” ;
core_string += “<tr rel=event_free_ticketed_multi_day_same_oc>”;
core_string += “<td>Close</td><td align = ‘left’><small>  HH    MM<br><input name=’close_hours_a’ type=’text’ size=’1′>:<input name=’close_minutes_a’ type=’text’ size=’1′><input name=’close_ap_a’ type=’radio’ value=’AM’>AM<input name=’close_ap_a’ type=’radio’ value=’PM’>PM</small></td></tr>”;
//function to create another field
function create_another_field(output){
//increase the number of field repititions by one
repititions_of_fields = repititions_of_fields + 1;
//produce the html
output.innerHTML = “”;
var str = ”;
//start the table
str = ‘<table border=”4″ style=”border-collapse:collapse;”>n’;
//repeat the fields
for (var x=0; x<repititions_of_fields; ++x){str += core_string;}
//end the table
str += “</table>n”;
//output the string to html
output.innerHTML = str;
}
function remove_a_field(output){
//decrease the number of fields if repititions > 0
if(repititions_of_fields>0){repititions_of_fields = repititions_of_fields – 1;}
//produce the html
output.innerHTML = “”;
var str = ”;
//start the table
str = ‘<table border=”4″ style=”border-collapse:collapse;”>n’;
//repeat the fields
for (var x=0; x<repititions_of_fields; ++x){str += core_string;}
//end the table
str += “</table>n”;
//output the string to html
output.innerHTML = str;
}
window.onload = function(){
var f = document.forms[‘ScheduleForm’], ele = f.elements;
ele[‘sessions_no’].onclick = function()
{return remove_a_field(document.getElementById(‘ScheduleArea’));}
ele[‘sessions_yes’].onclick = function()
{return create_another_field(document.getElementById(‘ScheduleArea’));}
}
</script>
</head>
<body>
<noscript><p>Sorry, this page requires JavaScript to be available and enabled.</p></noscript>
<div style=”text-align:center”>
<form name=”ScheduleForm” action=”test_rego_generate_event_schedule.php” method=”post”>
Would you like to add another group of sessions? <input type=”button” name=”sessions_yes” value=”Yes”><br><br>
Would you like to remove a group of sessions? <input type=”button” name=”sessions_no” value=”Yes”><br><br>
<div id=”ScheduleArea”> </div>
</form>
</div>
</body>
</html>