• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 673
  • Last Modified:

document.getElementById

When I try to use the following script I get an error that says
document.getElementById is not a function
I have looked this up and it appears that netscape 4.X does not support the
document.getElementById but unfortunately that is the version that I have to write my page for does anyone have a suggestion on a possible replacement for this code.
Also I am not even certain that this is the only error that I would receive once if that actually worked
This is a very nice script I found at http://www.xs4all.nl/~ppk/js/domform.html

Here is the code:

<script language="JavaScript" type="text/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);
}

window.onload = moreFields;
</script>


<div id="readroot" style="display: none">
     <p class="hr"> </p>

     <input type="button" value="Remove review" style="font-size: 10px"
          onClick="
               this.parentNode.parentNode.removeChild(this.parentNode);
          "><br><br>

     <input name="cd_1" value="title">

     <select name="rankingsel_1">
          <option>Rating</option>
          <option value="excellent">Excellent</option>
          <option value="good">Good</option>
          <option value="ok">OK</option>
          <option value="poor">Poor</option>
          <option value="bad">Bad</option>
     </select><br><br>

     <textarea name="review_1">Short review</textarea>

</div>

<form>
<span id="writeroot"></span>

<input type="button" value="Give me more fields!" onClick="moreFields()">
<input type="button" value="Send form" onClick="alert('Fake submit')">

</form>
0
davidtrina
Asked:
davidtrina
1 Solution
 
ahosangCommented:
No, it's a DOM script that won't be possible for NS4.x
That's the thing with NS 4.x it's obsolete!! You won't be able to do many of the powerful things you can so easily do with newer browsers.
0
 
bjorsqCommented:
There are a couple of ways to replace this code for Netscape:
1. do the whole lot using a server-side script. Each time the user clicks the button, send the form to the script which then writes a new form for you.
2. do it using a frameset with dynamically written frames - have one frame containing the scripts to write out form elements, and buttons to prompt the user for action, and the other to display the form (written dynamically by the first frame using document.write()).

0
 
jaysolomonCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Accept: ahosang {http:#8224222}

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jAy
EE Cleanup Volunteer
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now