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 7531553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:12:10+00:00 2026-05-30T05:12:10+00:00

Im making a form validation and im creating a dom dynamically but when I

  • 0

Im making a form validation and im creating a dom dynamically but when I press the submit button to create the error it is calling the element multiple times instead of once. So how can I make it call it once? Im a little lost on this one.

Javascript:

function validateForm(){
var xfields=document.forms["form1"]["amt"].value;
if (xfields==null || xfields==""){
  var errortag = document.createElement('label');
  var realinput = document.getElementById('amt');
  var errortagname = 'error';
  errortag.setAttribute('class',errortagname);
  errortag.innerHTML = 'Amount of loan needed';
  var adddiv = document.getElementById('amtloan').insertBefore(errortag, realinput.nextSibling);
  if(adddiv === true){
      document.getElementById('amtloan').insertBefore(errortag, realinput.nextSibling);
  return false;
      }else{
        xfields.remove('errortag');
    }
}
  return true;
}

HTML

<div id="st-widget" style=" width: 393px; padding-bottom: 0;">
<form class="ui-form ui-widget-form" id="short_form" method="get" name="form1" target="_blank" onsubmit="return validateForm()">
      <input type="hidden" > <input id="scl" name="scl" type="hidden" value=""> 
      <input name="optInQ" type="hidden" value="t">
      <input name="inplst" type="hidden" value="BSGAEOZ">

    <div class="grad-date" style="clear:left; #width:138px;">
       <label for="gradDate">When will you graduate?</label>
           <select id="gradDate" name="gradDate" style="width:46px !important;"    tabindex="10" title="Month">
              <option selected="selected" value="">Month</option>
              <option value="January">January</option>
              <option value="February">February</option>
              <option value="March">March</option>
              <option value="April">April</option>
              <option value="May">May</option>
              <option value="June">June</option>
              <option value="July">July</option>
              <option value="August">August</option>
              <option value="September">September</option>
              <option value="October">October</option>
              <option value="November">November</option>
              <option value="December">December</option>
          </select>
          <select id="grad-month" name="gradDate" style="width:46px !important;" tabindex="15" title="Year">
              <option selected="selected" value="">Year</option>
              <option value="2011">2011</option>
              <option value="2012">2012</option>
              <option value="2013">2013</option>
              <option value="2014">2014</option>
              <option value="2015">2015</option>
              <option value="2016">2016</option>
              <option value="2017">2017</option>
          </select>
    </div>
    <div id="amtloan" class="amount">
        <label for="amt">Amount of loan needed?</label>
           <input class="amt-input required" id="amt" name="amt" style="width:137px;" tabindex="20" title="Amount of loan needed" type="text" value="">
    </div>
    <div class="ui-form-action" style="margin-top:18px;">
       <button class="ui-btn button" id="" name="go" tabindex="35" title="GO" type="submit" value="Submit">
      <span class="ui-btn-ctn medium">Continue </span>
   </button>
</div>
</form></div></div>
  • 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-05-30T05:12:11+00:00Added an answer on May 30, 2026 at 5:12 am

    This line

    var adddiv = document.getElementById('amtloan').insertBefore(errortag, realinput.nextSibling);
    

    causes the errortag to be inserted every time you call the validator function. Try

        //...    
        var adddiv = document.getElementsByClassName(errortagname).length == 0;
        if(adddiv === true){
            document.getElementById('amtloan').insertBefore(errortag, realinput.nextSibling);
        }
        return false;
    }
    

    Not sure what the else clause is supposed to do though.

    There is a lot of potential for improvement, but I think Stackoverflow is not the right place to discuss the code in great detail.

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

Sidebar

Related Questions

I'm making a simple form to create polls, therefore I want the possibility to
I've been making this login form in C# and I wanted to 'submit' all
I want to create a form for making a reservation for borrowed items. A
I'm making a form that I'm using the amazing JQuery validation plugin for (
I'm making a simple form with an input field implementing Bean Validation. All of
I'm using jQuery Validate for my form validation. I'm making an Ajax call to
I am writing my own form validation plugin. I am making to work with
i am making a user registration form with validation.thats my simple form field. <tr>
I am working on making server side validation for a form. Using AJAX, the
I am making a form to search for colleges based on athletic programs offered

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.