Hi and sorry for my English I speak french,
I want to use dynamic field in my forms so I use this code
But I have two problems:
1- I cannot change dynamically the name of the fields. The command “newField[i].name=theName+counter;” doesn’t work. Do you have a command that work.
2- I want to do that for a professor I can add many course, any course have the name and the hour and I have a table of professor that have a 1 to n relationship with the table course. How can store all the course of a professor ? I only need to store in the table of course the id of the professor for all his course. How can I do that?
I want to use dynamic field in my forms so I use this code
<html>
<div id="readroot" style="display: none">
<div class="form_item">
<div class="form_element cf_textbox">
<label class="cf_label" style="width: 150px;">Product:<span class="star-red">*</span>:</label>
<input maxlength="150" size="30" title="" id="" name="" type="text" />
</div>
<div class="form_element cf_textarea">
<label class="cf_label" style="width: 150px;">Price:</label>
<textarea class="cf_inputbox" rows="2" id="text_12" title="Please add specific details" cols="24" name="notesurl_1"></textarea>
</div>
</div>
<input type="button" value="Remove Product"
onclick="this.parentNode.parentNode.removeChild(this.parentNode);" /><br /><br />
</div>
<!--end of hidden box -->
<!-- start form -->
<div class="form_item">
<div class="form_element cf_textbox">
<label class="cf_label" style="width: 150px;">Product:</label>
<input maxlength="150" size="30" title="" id="text_4" name="url_1" type="text" />
</div>
<div class="form_element cf_textarea">
<label class="cf_label" style="width: 150px;">Price:</label>
<textarea rows="2" id="text_12" title="Please add specific details" cols="24" name="notesurl_1"></textarea>
<div class="cfclear"> <img src="images/system/horizontal-line.png" width="438" height="1" /></div>
<div class="cfclear"> </div>
</div>
</div>
<span id="writeroot"></span>
<input type="button" value="Add Product" onclick="moreFields()" />
</html>
<javascript>
var counter = 0;
function moreFields() {
counter++;
var newFields = document.getElementById('readroot').cloneNode(true);
newFields.id = '';
newFields.style.display = 'block';
var newField = newFields.childNodes;
for (var i=0;i<newField.length;i++) {
var theName = newField[i].name
if (theName)
newField[i].name = theName + counter;
}
var insertHere = document.getElementById('writeroot');
insertHere.parentNode.insertBefore(newFields,insertHere);
}
</javascript>
But I have two problems:
1- I cannot change dynamically the name of the fields. The command “newField[i].name=theName+counter;” doesn’t work. Do you have a command that work.
2- I want to do that for a professor I can add many course, any course have the name and the hour and I have a table of professor that have a 1 to n relationship with the table course. How can store all the course of a professor ? I only need to store in the table of course the id of the professor for all his course. How can I do that?