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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:14:07+00:00 2026-06-11T22:14:07+00:00

is there a way to write the same thing clientside using javascript to multiple

  • 0

is there a way to write the same thing clientside using javascript to multiple divs or multiple spots on a page?

I have a php script outputting rows from a database. To edit the contents, I would like to insert a checkbox before each row as with the iphone edit contacts and to do it quickly, I’m trying to use javascript to populate a div with a checkbox before each row using getElemenByID.

One problem is you cannot have more than one div of the same name on a page so I can’t write once and have it populate multiple divs of the same name. If I give divs different names than I have to write multiple times which is not appealing especially as the number of rows may vary.

As a related question would checkboxes inserted using javascript even work?

Here is non working code:

js

function edit() }
var box = '<input type="checkbox name=num[]>';
var target = "checkbox";
document.getElementById(target).innerHTML = box;
return;
}//end function

html (generated by PHP from dbase)

<form action="edit.php" method="post">
<a href="javascript:void" onclick="edit()";>edit</a>
<div id="checkbox"></div>Row1 contents<br>
<div id="checkbox"></div>Row2 contents<br>
<form type = "submit" value="Edit">
</form>

Does anyone know a way to do this ie make boxes appear that can then be selected for submission?

Many thanks for any suggestions.

  • 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-11T22:14:08+00:00Added an answer on June 11, 2026 at 10:14 pm

    Should be generated using PHP instead, but…

    HTML

    I’m guessing that you want to use a span element (not a div) for your checkbox placeholder, otherwise you’d have a checkbox on one line, and then “Row1 contents” below the checkbox, versus having the checkbox next to the text.

    [X]
    Row 1 Contents
    

    versus (span)

    [X] Row 1 Contents
    

     

    <form action="edit.php" method="post" name="frmRows" id="frmRows">
        <a href="javascript:void(0)" onclick="edit()">edit</a>
        <span class="checkbox"></span>Row1 contents<br>
        <span class="checkbox"></span>Row2 contents<br>
        <input type = "submit" value="Edit">
    </form>
    

    JavaScript

    It’s not recommended to use .innerHTML in JavaScript unless absolutely necessary (not supported in all browsers, and there are better ways to accomplish the same task.)

    function edit() {
        var newCb;
        var i;
        var checkboxList = document.getElementsByClassName( 'checkbox' );
    
        for ( i = 0; i < checkboxList.length; i++ ) {
    
            newCb = document.createElement( 'input' ); // Create a new input element
    
            newCb.setAttribute( 'type', 'checkbox' ); // Set attributes for new element
            newCb.setAttribute( 'value', 'SomeValueHere' );
            newCb.setAttribute( 'name', 'checkboxName' );
            newCb.setAttribute( 'id', 'checkbox-' + i );
    
            checkboxList[i].appendChild( newCB ); // Add checkbox to span.checkbox
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to write a single LINQ expression to get the same
Is there any way to write Shoes application using IDE (NetBeans for example)? I
Is there a way to write something like this with Mojo::UserAgent ,having the possibility
Is there any way to write a valid header/link/image? Something like <a href=index.html><h1 id=logo>Company
Is there any way to write to a text file in Flex 4.6? Its
Is there a way to write in Visual Studio in nice formated way the
Is there a way to write in a app.config file the information about endpoints?
Is there a way to write a Java Swing application with a custom chrome?
Is there a way to write this C/C++ code in Python? a = (b
Is there any way to write binary output to sys.stdout in Python 2.x? In

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.