Skip to main content

Outputting values of select options in specific HTML structure on selection

I want to output the values that become visible when selecting an option in the dropdown into the table structure that is now visible as an example. Edit: The table is just as an example how I want the output to be after selecting an option, I don’t want the table to -always- be visible and insert selections into it. So my guess is that the table structure should be set up after .innerHTML or something and declare the values at the right places into the table?

Any help will be greatly appreciated.

function selectedAfternoon(element) {
  var text = element.options[element.selectedIndex].value;
  document.getElementById("output-selected-option-afternoon").innerHTML = "<div>" + text.split("|").join("</div><div>") + "</div>";
  document.getElementById("output-selected-option-afternoon").querySelector("div:last-child").classList.add("price-selected-option")
}
.selected-option {
  display: flex;
  width: 100%;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
}
<select id="namiddag" name="Namiddag" data-name="Namiddag" class="js-basic-single select-namiddag" onChange="selectedAfternoon(this);">
  <option></option>
  <option id="13x19namiddag" value="13x19 cm|1|12,50">13x19 cm, €12.50</option>
  <option id="20x30namiddag" value="20x30 cm|1|22,50">20x30 cm, €22.50</option>
  <option id="30x45namiddag" value="30x45 cm|1|32,50">30x45 cm, €32.50</option>
  <option class="disabled" value="disabled" disabled="disabled">Wil je meer stuks of formaten van deze foto? Vermeld dit dan in de winkelwagen., &nbsp;</option>
</select>

<div id="output-selected-option-afternoon" class="selected-option"></div>


<table>
<thead>
  <tr>
    <th>Format</th>
    <th>Amount</th>
    <th>Price</th>
  </tr>
</thead>
<tbody>
  <tr>
    <td>13x19 cm</td>
    <td>1</td>
    <td class="price-selected-option">12,50</td>
  </tr>
</tbody>
</table>
function selectedAfternoon(element) {
  var text = element.options[element.selectedIndex].value;
  let tableBody = document.getElementById('selected-option-table-afternoon');

  const [format, amount, price] = text.split("|")

  tableBody.innerHTML = `<tr>
                <td>${format}</td>
                <td>${amount}</td>
                <td>${price}</td>
                </tr>`
}

function selectedCommute(element) {
  var text = element.options[element.selectedIndex].value;
  let tableBody = document.getElementById('selected-option-table-commute');

  const [format, amount, price] = text.split("|")

  tableBody.innerHTML = `<tr>
                <td>${format}</td>
                <td>${amount}</td>
                <td>${price}</td>
                </tr>`
}
<select id="namiddag" name="Namiddag" data-name="Namiddag" class="js-basic-single select-namiddag" onChange="selectedAfternoon(this);">
  <option></option>
  <option id="13x19namiddag" value="13x19 cm|1|12,50">13x19 cm, €12.50</option>
  <option id="20x30namiddag" value="20x30 cm|1|22,50">20x30 cm, €22.50</option>
  <option id="30x45namiddag" value="30x45 cm|1|32,50">30x45 cm, €32.50</option>
  <option class="disabled" value="disabled" disabled="disabled">Wil je meer stuks of formaten van deze foto? Vermeld dit dan in de winkelwagen., &nbsp;</option>
</select>

<select id="onderweg" name="Onderweg" data-name="Onderweg" class="js-basic-single select-onderweg" onChange="selectedCommute(this);">
  <option></option>
  <option id="13x19onderweg" value="13x19 cm|1|12,50">13x19 cm, €12.50</option>
  <option id="20x30onderweg" value="20x30 cm|1|22,50">20x30 cm, €22.50</option>
  <option id="30x45onderweg" value="30x45 cm|1|32,50">30x45 cm, €32.50</option>
  <option class="disabled" value="disabled" disabled="disabled">Wil je meer stuks of formaten van deze foto? Vermeld dit dan in de winkelwagen., &nbsp;</option>
</select>

<div id="output-selected-option-afternoon" class="selected-option">
  <table>
    <thead>
      <tr>
        <th>Format</th>
        <th>Amount</th>
        <th>Price</th>
      </tr>
    </thead>
    <tbody id="selected-option-table-afternoon">
      <tr>
        <td></td>
        <td></td>
        <td class="price-selected-option"></td>
      </tr>
    </tbody>
  </table>
</div>

<div id="output-selected-option-commute" class="selected-option">
  <table>
    <thead>
      <tr>
        <th>Format</th>
        <th>Amount</th>
        <th>Price</th>
      </tr>
    </thead>
    <tbody id="selected-option-table-commute">
      <tr>
        <td></td>
        <td></td>
        <td class="price-selected-option"></td>
      </tr>
    </tbody>
  </table>
</div>
Via Active questions tagged javascript - Stack Overflow https://ift.tt/Z7KLNyP

Comments

Popular posts from this blog

How to show number of registered users in Laravel based on usertype?

i'm trying to display data from the database in the admin dashboard i used this: <?php use Illuminate\Support\Facades\DB; $users = DB::table('users')->count(); echo $users; ?> and i have successfully get the correct data from the database but what if i want to display a specific data for example in this user table there is "usertype" that specify if the user is normal user or admin i want to user the same code above but to display a specific usertype i tried this: <?php use Illuminate\Support\Facades\DB; $users = DB::table('users')->count()->WHERE usertype =admin; echo $users; ?> but it didn't work, what am i doing wrong? source https://stackoverflow.com/questions/68199726/how-to-show-number-of-registered-users-in-laravel-based-on-usertype

Why is my reports service not connecting?

I am trying to pull some data from a Postgres database using Node.js and node-postures but I can't figure out why my service isn't connecting. my routes/index.js file: const express = require('express'); const router = express.Router(); const ordersCountController = require('../controllers/ordersCountController'); const ordersController = require('../controllers/ordersController'); const weeklyReportsController = require('../controllers/weeklyReportsController'); router.get('/orders_count', ordersCountController); router.get('/orders', ordersController); router.get('/weekly_reports', weeklyReportsController); module.exports = router; My controllers/weeklyReportsController.js file: const weeklyReportsService = require('../services/weeklyReportsService'); const weeklyReportsController = async (req, res) => { try { const data = await weeklyReportsService; res.json({data}) console

How to split a rinex file if I need 24 hours data

Trying to divide rinex file using the command gfzrnx but getting this error. While doing that getting this error msg 'gfzrnx' is not recognized as an internal or external command Trying to split rinex file using the command gfzrnx. also install'gfzrnx'. my doubt is I need to run this program in 'gfzrnx' or in 'cmdprompt'. I am expecting a rinex file with 24 hrs or 1 day data.I Have 48 hrs data in RINEX format. Please help me to solve this issue. source https://stackoverflow.com/questions/75385367/how-to-split-a-rinex-file-if-i-need-24-hours-data