/    Sign up×
Community /Pin to ProfileBookmark

checkbox array with ID and VALUE attributes

Helly ladies and gents,

I have a dynamic set of 120 checkboxes that are rendered with php:

[code=php]echo “<input type=”checkbox” id=””. $prosubline[“sku”] .”” value=”” . $prosubline[“price”] .”” name=”products[]”/>n”;
[/code]

  • I have the ID attribute to have the SKU number of the product

  • I have the VALUE has the price so a javascript function will display the total as the click on the desired product on the fly

  • I have the NAME attribute so PHP will render my “products[]” array on a results page with the follwing code:
  • [code=php]
    echo “<p>here are the products you selected:</p>”;

    $real_selection = “”;

    foreach ($_POST[“products”] as $id)
    {
    if ($real_selection)
    $real_selection .= “, “.trim($id);
    else
    $real_selection = trim($id);
    }
    echo $real_selection;
    [/code]

    The problem is that the results page displays the checked products but displays the prices in a sentence which is what the VALUE attribute on the form has. Is it possible for PHP to fetch the ID value instead of the actual VALUE attribute from the checkbox field so I can have the SKU of the products? I am trying to fetch those values into a QUERY on the results page if I can get that to work. any suggestions..are appreciated :rolleyes:

    to post a comment
    PHP

    0Be the first to comment 😎

    ×

    Success!

    Help @vicpal25 spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 6.2,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,

    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,

    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,
    )...