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

  • Home
  • SEARCH
  • 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 7848119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:05:26+00:00 2026-06-02T18:05:26+00:00

<script type=text/javascript> var a = new Array(); function obj(type, value) { this.type = type;

  • 0
<script type="text/javascript">
    var a = new Array();
    function obj(type, value) {
        this.type = type;
        this.value = value;
        this.toStr = toStr
    }

    function toStr() {
        if (this.type == "select") {
            var temp = "";
            var arr = this.value.split("/");
            for (i = 0; i < arr.length; i++) {
                temp += "<option>" + arr[i] + "</option>"
            }
            return "<select>" + temp + "</select><br>";
        } else
            return "<input type = '" + this.type + "' value = '" + this.value + "'><br>";
    }

    function addObj(type) {
        var sel = parent.frames["left"].document.form1.q.value;
        for (i = 0; i < sel; i++)
            a[a.length] = new obj(type,
                    parent.frames["left"].document.form1.caption_text.value,
                    a.length);
        paint();
        parent.frames["left"].document.form1.caption_text.value = "";
    }

    function paint() {
        parent.frames["right"].document.open()
        for (i = 0; i < a.length; i++)
            parent.frames["right"].document.writeln(a[i].toStr())
        parent.frames["right"].document.close()
    }
</script>
<form name=form1>
    <table>
        <tr>
            <td><input type="button" style="width: 150px" value="Add Button" onClick="addObj('button')"><br />
                <input type="button" style="width: 150px" value="Add TexBox" onClick="addObj('text')" /><br />
                <input type="button" style="width: 150px" value="Add Select" onClick="addObj('select')" /></td>
            <td>Text : <br /> Number of adding elements:<br /></td>
            <td><input type="text" name="caption_text" style="width: 150px"> <br /> <select
                NAME=q size=1 style="width: 150px">
                    <option selected value="1">1</option>
                    <option value="2">2</option>
                    <option value="3">3</option>
                    <option value="4">4</option>
                    <option value="5">5</option>
            </select></td>
        </tr>
    </table>
</FORM>

enter image description here

Code is corrupting when creating select elements.
What’s wrong with this code?

Thanks in advance.

  • 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-02T18:05:28+00:00Added an answer on June 2, 2026 at 6:05 pm

    Your i variables are missing a var declaration. All loops use the same counter, which means that nested loops will break horribly. My suggestion:

    var a = [];
    function FormElement(type, value) {
        this.type = type;
        this.value = value;
    }
    
    FormElement.prototype.toString = function toStr(){
        if (this.type == "select") {
            var arr = this.value.split("/");
            for (var i = 0; i < arr.length; i++) {
                arr[i] = "<option>" + arr[i] + "</option>"
            }
            return "<select>" + arr.join("") + "</select><br />";
        } else
            return "<input type = '" + this.type + "' value = '" + this.value + "' /><br />";
    };
    
    function addObj(type) {
        var form = parent.frames["left"].document.form1; 
        var sel = form.q.value;
        for (var i = 0; i < sel; i++)
            a.push(new FormElement(type, form.caption_text.value);
        paint();
        form.caption_text.value = "";
    }
    
    function paint() {
        var doc = parent.frames["right"].document;
        doc.open();
        doc.write(a.join("\n"));
        doc.close();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is the JS <SCRIPT type=text/javascript> $(function() { var ids = new Array(); for(var
I have this code <title>Welcome</title> <head> <script type=text/javascript> var id = ...; var sessionCount
Here is fragments of my HAML view: %script{:type => text/javascript, :src => assets/application.js} :javascript
I have this jQuery script var dataString = class_id=+class_id; $.ajax({ type: POST, url: page.php,
I have a jQuery script: $.ajax({ url: /scripts/secure/development/ajax.asp, type: POST, dataType: text, data: cmd=addresses,
I am currently using this script to get new data every second from record_count.php
I've tried to change filenames using following script: find dir/ -type f -exec mv
I am calling a service that return JSON data. Script: $.ajax({ type: "POST", url:
OK I have a simple script at http://kleague.org/test/ Type a movie name and it
I have a Perl script called replaceUp: #!/usr/bin/perl search=$1 replace=$2 find . -type f

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.