1

this is my code, how can i place javascript data attribute in form_input() codeigniter??

$experience=array(
    'name'=>'experience',
    'class'=>'slider tags',
    'id'=>'experience',
    'data-slider-min'=>1,
    'data-slider-max'=>15,
    'data-slider-step'=>1,
    'data-slider-value'=>[5,10]
);
echo form_input($experience); ?>

3 Answers 3

1

Look at this code it might help you to overcome this issue

                        <?php
                        $experience=array(
                            'name'=>'experience',
                            'class'=>'slider tags',
                            'id'=>'experience',
                            'data-slider-min'=>0,
                            'data-slider-max'=>15,
                            'data-slider-step'=>1,
                            'data-slider-value'=>['5','10'],
                            'value'=>3,4

                        );
                      echo form_input($experience); 
                    ?>
Sign up to request clarification or add additional context in comments.

Comments

0

Have you tried simply moving your JS attributes into the $experience variable that you use to create the input?

$experience=array(
    'name'=>'experience',
    'class'=>'slider tags',
    'id'=>'experience',
    'data-slider-min' => 1,
    'data-slider-max' => 15,
);

etc...

4 Comments

@M.Athishkrishna Can you please show your newly edited code in your original post?
Have you seen that?@Leprichaun
Put single quotes around the last attribute, just like you did with name, id and class. The numbers don't need quotes, but the last one does as it's treated as a string.
No worries my friend. Don't forget to select this as the answer to help anybody that comes across it in future :)
0

// HTML Code

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <link rel="stylesheet" type="text/css" href="style.css" />
    <script src="main.js"></script>
  </head>
  <body>
    <li class="item" data-done-state="true">Erster Eintrag</li>
    <li class="item" data-done-state="false">Zweiter Eintrag</li>
    <li class="item" data-done-state="true">Dritter Eintrag</li>
  </body>
</html>

//CSS Code

li {
  background-color: khaki;
  margin: 2px;
  padding: 2px;
}

[data-done-state="true"] {
  text-decoration: line-through;
}

//JS Code

window.onload = function() {
  const nodes = document.querySelectorAll(".item");
  for (const node of nodes) {
    node.addEventListener("click", function(elem) {
      switchDoneState(elem);
    });
  }
};

function switchDoneState(elem) {
  const isDone = JSON.parse(elem.target.getAttribute("data-done-state"));
  elem.target.setAttribute("data-done-state", !isDone);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.