javascript - How to get selected Text in a HTML drop down using dynamic ID -
i trying pull values json string on web page. have used dynamic id in select drop-down. want create if loop such compares if selected value in drop down equal "some text" should print result in field. here want final value in place of "i want value here". here piece of code.
<div class="row"> <span class="input-field col wide20"> <input readonly="readonly" type="text" value="" class="form-control" id="<?php echo $key; ?>_name_broker" placeholder=""> </span> <span class="input-field col wide20"> <!--input type="text" class="form-control" placeholder=""--> <select style="width: 100%;" name="mapped_broker" class="form-control mappedbroker" data-id="<?php echo $key; ?>" id="<?php echo $key; ?>_select_broker"> <option value="">--select--</option> <?php foreach ($my_array_data['brokername'] $data2){ ($i = 0; $i < count($data2['entityname']); $i++) { ?> <option value="<?php echo $data2['senetence']; ?>"><?php echo $data2['entityname']; ?></option> <?php } } ?> </select> <input style="display:none;" type="text" id="<?php echo $key; ?>_edit_broker" name="edited_sub_broker"> </span> <span class="input-field col wide20"> <button type="submit" class="btn btn-dark-grey">broker</button> </span> <span class="input-field col wide10"> <span class="icon-edit" id="span_edit_broker"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" enable-background="new 0 0 64 64" id="layer_1" version="1.1" viewbox="0 0 64 64" xml:space="preserve"> <g> <path d="m55.736 13.636l-4.368-4.362c-0.451-0.451-1.044-0.677-1.636-0.677 -0.592 0-1.184 0.225-1.635 0.676l-3.494 3.484 7.639 7.626 3.494-3.483c56.639 15.998 56.639 14.535 55.736 13.636z"/> <polygon points="21.922 35.396 29.562 43.023 50.607 22.017 42.967 14.39 "/> <polygon points="20.273 37.028 18.642 46.28 27.913 44.654 "/> <path d="m41.393 50.403h12.587v21.597h20.329l5.01-5h10.82c-1.779 0-3.234 1.455-3.234 3.234v32.339c0 1.779 1.455 3.234 3.234 3.234h32.339c1.779 0 3.234-1.455 3.234-3.234v29.049l-5 4.991v50.403z"/> </g> </svg> </span> </span> <span class="input-field col wide20"> <input readonly="readonly" type="text" class="form-control" placeholder="" name="brokersuggestion" value="<?php echo $jsonarrdata['brokersuggestion'] ? >"> </span> <span class="input-field col wide10"> <input readonly="readonly" type="text" value="" class="form-control" id="<?php echo $key; ?>_conf_broker" placeholder="i want value here" </span> </div> edit: json looks this.
"brokername": [ { "entityname": "amwins", "entitytype": "brokername", "filetype": "email", "orignalfilename": "fw american hospitality association inc - gl sub- eff 7 27.msg", "orignalfile": "e:\\emails\\80 submission\u0027s email\\fw american hospitality association inc - gl sub- eff 7 27.msg", "extlfilename": "msg_americanhospitalityassociation.txt", "extfilepath": "e:\\80 txt\\americanhospitalityassociationinc-glsub-eff727\\msg_americanhospitalityassociation.txt", "senetence": "o quote . thank jessica tonkinson vice president amwins", "confidence": 0.1 },
here's working fiddle might guide in correct direction.
here listening change event on selection , comparing value whatever want.
<select class="selection"> <option value="one">one</option> <option value="two">two</option> <option value="three">three</option> </select> note added class selection make sure trigger when specific selection changes value
$(".selection").change((e)=>{ if(e.target.value == "two"){ console.log("tada"); }else{ console.log("wrong"); } }) you said needed code on page itself, wrap inside <script>tag , should good.
edit: don't want give whole bunch of code, since think can figure out there, here's little bit of help:
$(".selection").change((e)=>{ let yourentityname = e.target.val; // <--- selection }) this how string of chosen entity. now, needs compared json object, whatever corresponding string want, right?
well, need search on entries in brokername array find correct entry (assuming there more one, right?) assume array json named brokernamearr
let correspondingstuffweneed = ""; for( let = 0; < brokernamearr.length; i++){ if(brokernamearr[i]["entityname"] == yourentityname){ correspondingstuffweneed = brokernamearr[i]["whateveryouneed"]; break; //since got wanted } } and stuff above gets packed inside change event (or inside method , called, choice) , have value need.
Comments
Post a Comment