So habe ich eine Liste der Dropdown-Auswahl automatisch aus der Datenbank generiert und für jede von ihnen habe ich eine Textarea automatisch erstellt.Füllen Sie Textarea indiviuduell mit Auswahl aus php erstellten Liste von Dropdowns
Hier ist der html/PHP-Code:
<div class="row options-content">
<?php if ($options) { ?>
<?php foreach ($options as $option) { ?>
<?php if ($option['type'] == 'select') { ?>
<div class="form-group<?php echo ($option['required'] ? ' required' : ''); ?>">
<label class="control-label" for="input-option<?php echo $option['product_option_id']; ?>"><?php echo $option['name']; ?></label>
<select name="option[<?php echo $option['product_option_id']; ?>]" id="input-option<?php echo $option['product_option_id']; ?>" class="form-control">
<option value=""><?php echo $text_select; ?></option>
<?php foreach ($option['product_option_value'] as $option_value) { ?>
<option value="<?php echo $option_value['product_option_value_id']; ?>"><?php echo $option_value['name']; ?>
<?php if ($option_value['price']) { ?>
(<?php echo $option_value['price_prefix']; ?><?php echo $option_value['price']; ?>)
<?php } ?>
</option>
<?php } ?>
</select>
</div>
<textarea name="option-<?php echo $option['name']; ?>" rows="1" cols="50" class=""></textarea>
<?php } ?>
<?php } ?>
<?php } ?>
und hier ist die javascript:
<script>
$("select")
.change(function() {
var str = "";
$("select option:selected").each(function() {
str += $(this).text() + " ";
});
$("textarea").text(str);
})
.change();
</script>
Alles, außer dass, wenn die erste drowdown in ausgewählten, es scheint zu funktionieren Ändert den Text in allen anderen textarea ... Wie mache ich Änderungen nur im angegebenen Textfeld?
habe ich versucht, die folgenden aber dann funktioniert nichts mehr:
<script>
$("select")
.change(function() {
var str = "";
$("select option:selected").each(function() {
str += $(this).text() + " ";
});
$("#option-<?php echo $option['name']; ?>").text(str);
})
.change();
</script>
Können Sie das gerenderte HTML posten? –