Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8126363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T07:07:17+00:00 2026-06-06T07:07:17+00:00

Lets clarify my question, I want to make an element which the element contains

  • 0

Lets clarify my question,

I want to make an element which the element contains 5 fields so I dont want the user should be able to put in a new element if the old one is null, so I made the alert when looping through the old element and see if there is some strings, if not then dont put a new element and make an alert please fill out all fields

Here again my code

function addEvent() {
      var ni = document.getElementById('discount'); // Takes the a div named discount
      var discountForm = document.getElementById('discountForm'); // Takes the a form named discountForm
      var numi = document.getElementById('theValue'); // Takes the a hidden input field named theValue
      var num = (document.getElementById("theValue").value -1)+ 2; // Start counting to set the new divs form numbers
      numi.value = num;
      var divIdName = "my"+num+"Div"; // the new divs will be named
      var allDivTags = discountForm.getElementsByTagName('div'); // take all div tags
      var numOfDivs = (allDivTags.length -1); // take the number of the old div
      var oldDivIdName = document.getElementById(allDivTags[numOfDivs].id); // old div id
      var newdiv = document.createElement('div'); //the new div
      newdiv.setAttribute("id",divIdName);
      newdiv.innerHTML = "Company <select name=\"company[]\"><option value=\"\"></option><option value=\"ZI\">Avis</option><option value=\"ET\">Enterprise</option><option value=\"ZE\">Hertz</option><option value=\"ZD\">Budget</option><option value=\"ZR\">National</option><option value=\"AL\">Alamo</option></select> Discount Type <select name=\"type[]\"><option value=\"CD\">Discount Number</option><option value=\"PC\">Coupon Number</option></select> Code <input name=\"code[]\" type=\"text\"> Title <input name=\"title[]\" type=\"text\"> <a href=\"javascript:;\" onclick=\"removeElement(\'"+divIdName+"\')\">Remove</a>"; // creating the fileds in the new div
      ni.appendChild(newdiv);
      for(i=0; i<discountForm.elements.length;i++){ // loop through the divs
          if(numOfDivs != i-1){ // if tho old div exist and if the old div fields are empty
            if(oldDivIdName.children[i].value.length == 0){
              removeElement(divIdName); // then dont put the new one
              alert('Please enter all fields');
            }
          }
      }

    }

But my problem is that in IE comes out an error children[...].value.length is null or not an object so I trying to figure how to fix it,

I hope its more clearly for you now.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T07:07:20+00:00Added an answer on June 6, 2026 at 7:07 am

    It’s very hard to tell from the information you’ve given us. But my first guess is the following:

    for(i=0; i<discountForm.elements.length;i++){
      if(numOfDivs != i-1){
        if(oldDivIdName.children[i].value.length == 0){
          removeElement(divIdName);
          alert('Please enter all fields');
        }
      }
    }
    

    Above you’re doing:

    oldDivIdName.children[i]
    

    But i is defined as the number of elements in the form from what I can see… not the number of children of the oldDivIdName. If there are more elements in the form than there are in oldDivIdName then the value of oldDivIdName.children[i] will be null. And “value” is not defined on null.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets assume I've got an authorization token from user, that I will use later
Lets suppose I have a RESTful service which has a list of tasks. GET
I have a rather specific question perhaps.. I have a user that will enter
I'm building a little tool that lets user to place some geometric figures on
Let me clarify my question, and the solution I'm looking for. I'm using wikispaces.com,
I know this is very stupid question, but I wanted to clarify this. Let's
I have a table with an embedded picture(OLE) coulmn. I Want to be able
Edit 4: A new formatting for the question BACKGROUND: I have a class, Window,
A question regarding everything runs in parallel except your code from someone new to
While certain guidelines state that you should use an interface when you want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.