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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T20:17:08+00:00 2026-06-18T20:17:08+00:00

Simplified, I have a form that generate select boxes based on a mysql query.

  • 0

Simplified, I have a form that generate select boxes based on a mysql query.

$i = 0;
while($res= mysql_fetch_assoc($sql2))
echo "  <div class='span1'>";
echo "      <input name='orderNo[$i]' type='text' id='orderNo[$i]' value='$orderNo' class='input-small' onclick='populateorderNo()' />";
echo "  </div>";

echo "  <div class='span1'>";
echo "      <select name='methodOfPay[$i]' id='methodOfPay[$i]' class='input-small' >";
echo "      <option value=''>&nbsp;</option>";
echo "      <option value='On Bill'>On Bill</option>";
echo "      <option value='Customer C.C'>Customer C.C</option>";
echo "      <option value='Company G.C'>Company G.C</option>";
echo "      </select>";
echo "  </div>";
++$i;
}

What I am trying to do is copy the selected option on methodOFPay[0] to the succeeding methodOfPay[]’s. I was able to do it using an onclick function for orderNo, but I can’t figure out how to apply the same theory to a select box. Here is my js code for the simple text box copy. For now, it’s always going to be the first row copying to the succeeding rows.

var orderno = 0;
function populateorderNo(){
var copyorderNo = document.getElementById('orderNo[0]');
document.getElementById('orderNo[' + orderno + ']').value = copyorderNo.value;
orderno += 1;

}

Any help would be appreciated. Thank you very much, as a newbie, I am learning a lot from this site and all the answers I have received.

  • 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-18T20:17:10+00:00Added an answer on June 18, 2026 at 8:17 pm

    If you are using straight JavaScript you can use onchange. In jQuery, you can use .change().

    Straight JavaScript Method

    PHP

    echo "      <select name='methodOfPay[$i]' id='methodOfPay[$i]' class='input-small' onchange='myOnChangeFunction()' >";
     ...
    echo "      </select>";
    

    JS

    function myOnChangeFunction() {
        // Get value and set other selects
    }
    

    jQuery Method (jsfiddle)

    JS

    $('select[id^="methodOfPay"]').change(function() {
        var value = $(this).val();
        $('select[id^="methodOfPay"]').not($(this)).val(value);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form that looks similar to the following (simplified for brevity): PRICING_PATTERN
Greetings, I have a form with a variable number of inputs, a simplified version
I have the following layout in my page (simplified) <h:form> <h:commandButton action=#{bean.save} value=Save/> <rich:tabPanel
I have a table which contains TV Guide data. In a simplified form, the
I have a table in my database that represents datafields in a custom form.
I am creating a small web based tool that allows users to query a
[Note : I've simplified my example for clarity] Let's say that I have a
I have a form that will have dynamic elements inserted with javascript and am
I have a form that works just fine when I try it out (with
I trying to have a div with child divs that form 2 or more

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.