dynamic form2
I have this code:
Code:
<script type="text/javascript">
function addFields(field,area,count,limit)
{
if(count > limit && limit > 0) return;
switch (field)
case "download":
for (var i = 0; i < count; i++)
{
var dd = document.createElement("dd");
var input = document.createElement("input");
input.type="text";
input.name="download"+i;
input.id="download"+i;
dd.appendChild(input);
area.appendChild(dd);
}
break;
}
</script>
Code:
<dl>
<dt><label for="modauthor">Download Fields:</label></dt>
<dd><input type="text" name="dnum" id="dnum" size="3" maxlength="3" value="0" class="inputbox autowidth" /><input type="button" value="Set" onclick="addFields('download',document.getElementById(download_area),document.getElementById("dnum").value,0);" /></dd>
</dl>
Code:
<dl id="download_area">
</dl>
and I'm having some trouble with it.
1. The set button isn't calling the addFields function
2. I need this to either check how many fields there are already and either add to them or subtract from them. OR if it is easier, just remove all the fields and then re-add the correct amount. How would I do that?
I went for the easier route cause Im lazy right now :P
Code:
<script type="text/javascript">
function addFields(field, area, count, limit)
{
if(count > limit && limit > 0) return;
switch (field) {
case "download":
area.innerHTML = '';
for (var i = 0; i < count; i++) {
var dd = document.createElement("dd");
var input = document.createElement("input");
input.type = "text";
input.name = "download" + i;
input.id = "download" + i;
dd.appendChild(input);
area.appendChild(dd);
}
break;
}
}
</script>
<dl>
<dt><label for="modauthor">Download Fields:</label></dt>
<dd><input type="text" name="dnum" id="dnum" size="3" maxlength="3" value="0" class="inputbox autowidth" /><input type="button" value="Set" onclick="addFields('download',document.getElementById('download_area'),document.getElementById('dnum').value,0);" /></dd>
</dl>
<dl id="download_area">
</dl>
All code given is free and non-refundable.
Thanks, but the set button still never calls the function, what's wrong here?
You did use the button I submitted as well right? Cause there were quoting errors in your original one:
HTML Code:
<dl>
<dt> <label for="modauthor" > Download Fields:</label> </dt>
<dd> <input type="text" name="dnum" id="dnum" size="3" maxlength="3" value="0" class="inputbox autowidth" /> <input type="button" value="Set" onclick="addFields('download',document.getElementById('download_area'),document.getElementById('dnum').value,0);" /> </dd>
</dl>
All code given is free and non-refundable.
Originally Posted by
bionoid
You did use the button I submitted as well right? Cause there were quoting errors in your original one:
HTML Code:
<dl>
<dt> <label for="modauthor" > Download Fields:</label> </dt>
<dd> <input type="text" name="dnum" id="dnum" size="3" maxlength="3" value="0" class="inputbox autowidth" /> <input type="button" value="Set" onclick="addFields('download',document.getElementById('download_area'),document.getElementById('dnum').value,0);" /> </dd>
</dl>
Yes, i'm using your revised code, when I press the set button nothing happens and in the debugger the function is never called.
Originally Posted by
grimshad
Yes, i'm using your revised code, when I press the set button nothing happens and in the debugger the function is never called.
works fine for me. Maybe you should work on your copy and pasting before moving on to javascript, grimshad? This is the second time in two days that you've had this problem
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Bookmarks