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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:29:41+00:00 2026-05-24T20:29:41+00:00

I’m a javascript newbie so please, any help would be appreciate. I’ve been trying

  • 0

I’m a javascript newbie so please, any help would be appreciate. I’ve been trying to get selected values from a drop down list on my page in order to swap them . I’ve tried looking for solutions online but I’m stumped. For some reason, s1[i].selected doesn’t work at all. Here’s my javascript code:

<script type="text/javascript">
    function swaprows(s1, s2)
    {
        var items = "";
        var len = s1.length;
        for(i=0;i<len;i++)
        {
            if(s1[i].selected)
            {

            }
        }
    }       
</script>

The thing is I’m generating these listboxes on the fly using php, they’re not hard coded into my HTML. Here’s the code I use to create them and call the javascript function:

<form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">

    <ul>
    <?php
    do
    {
        echo "<li>";
        echo "<h2 class=\"expand\" >Choose the sizes for " . $product_array['Product Name'] . "\n</h2>";
        echo "<div class=\"collapse\">";
        echo "<table border=\"0\">";
        echo "<tr>";
        echo "<td rowspan=\"2\"><select size=\"8\" multiple=\"true\" name=\"selectsizes[]\" id=\"selectsizes\">\n";
        for($i=0; $i < sizeof($sizes_data); $i++)
        {
            echo "<option value=" . $sizes_data[$i]['Size ID'] . ">" . $sizes_data[$i]['Size Name'] . "</option>\n";
        }
        echo "</select></td>\n";

        echo "<td valign=\"top\"><input type = \"button\" OnClick=\"swaprows(this.form.selectsizes, this.form.selectedsizes);\" value=\"-->\" /></td>";

        echo "<td rowspan=\"2\"><select multiple=\"true\" name=\"selectedsizes[]\" id=\"selectedsizes\">\n";
        echo "</select></td>\n";

        echo "<td rowspan=\"2\" valign=\"bottom\"><input type=\"submit\" id=\"btnSubmit\" name=\"SaveSizes[" . $product_array['Product ID'] . "]\" value=\"Save\" /></td>";

        echo "</tr><tr>";

        echo "<td valign=\"top\"><input type = \"button\" OnClick=\"swaprows(this.form.selectedsizes, this.form.selectsizes);\" value=\"<--\" /></td>";         

        echo "</tr>";

        echo "</table>";

        echo "</li>";
    }while($product_array = mysql_fetch_assoc($product_result));    

    ?>
    </ul>
    </form>

Because I’m doing a post action with the submit buttons I need to name my lists as selectsizes[] and selectedsizes[] respectively so that I can then pass their selected values via the post variable. Can anyone help me out here?

  • 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-24T20:29:42+00:00Added an answer on May 24, 2026 at 8:29 pm

    I’m pretty sure you don’t need javascript for this.. just the [] in the name of the field. then on the other side php will auto make the array in the post variable of the selected fields.

    $sizes = $_POST['select_sizes'];
    $quantity = sizeof($sizes);
    $inc = 0;
    while ($inc < $quantity) {
        echo "User selected:".$sizes[$inc];
        $inc++;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I used javascript for loading a picture on my website depending on which small
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a bunch of posts stored in text files formatted in yaml/textile (from
I am trying to loop through a bunch of documents I have to put
Seemingly simple, but I cannot find anything relevant on the web. What is the
this is what i have right now Drawing an RSS feed into the php,

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.