简体   繁体   中英

input type range output is not working for dynamic id's

Input type range functionality is not working when the id values are dynamic how can i do that..?

 <input name="gdOverallscore" id="gdOverallscore" type="range" min="0" value="0" max="10" step="1" list="ticks" oninput="ageOutputId.value = gdOverallscore.value"/><output id="ageOutputId">0</output> <h2>This is working fine in my case i have dynamic id which is loop"</h2> <br> <input name="gdskill[<?php echo $skillLabel['ssid'];?>]" id="gdskill[<?php echo $skillLabel['ssid'];?>]" type="range" min="0" value="0" max="10" step="1" list="ticks" oninput="Output.value = gdskill[<?php echo $skillLabel['ssid'];?>].value"/> <output id="Output">0</output> <br> <h2> In the second one id values comes like this: gdskill[1],gdskill[3],gdskill[4],gdskill[6] etc.. </h2> 

Try using like this: Id like gdOverallscore[0] will not work.

 <?php

    $skillLabel['ssid']=10;

    ?>

    <input name="gdOverallscore" id="gdOverallscore" type="range" min="0" value="0" max="10" step="1" list="ticks" oninput="ageOutputId.value = gdOverallscore.value"/><output id="ageOutputId">0</output>


    <input  name="gdskill<?php echo  $skillLabel['ssid'];?>"
           id="gdskill<?php echo  $skillLabel['ssid'];?>" 
           type="range"
           min="0" value="0" max="10" step="1" 
           list="ticks" 
           oninput="Output.value = gdskill<?php echo  $skillLabel['ssid'];?>.value"/>
    <output id="Output">0</output>

In Case of MUltiple:

<?php

$skillLabel['ssid'][0]=10;
$skillLabel['ssid'][1]=11;

?>

<?php foreach($skillLabel['ssid'] as $key=>$value){?>
<input  name="gdskill<?php echo  $value;?>"
       id="gdskill<?php echo  $value;?>" 
       type="range"
       min="0" value="0" max="10" step="1" 
       list="ticks" 
       oninput="Output<?php echo  $value;?>.value = gdskill<?php echo  $value;?>.value"/>
<output id="Output<?php echo  $value;?>">0</output>

<?php }?>

DEMO

You have to change your Ouptut Id as well or else the output will become same for all hence it wont work..

<input name="[]" id="gdskill<?php echo  $skillLabel['ssid'];?>"

 type="range" min="0" value="0" max="10" step="1"

oninput="Output<?php echo  $skillLabel['ssid'];?>.value = gdskill<?php echo  $skillLabel['ssid'];?>.value"/>

<output id="Output<?php echo  $skillLabel['ssid'];?>">0</output>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM