0

I have a html field called styles, which gets its value from a php value:

<input name="styles" value="'.$colorstyle.'" id="styles" >

Now I have a javascript code, in which I need the value of the field to place in:

this.colours = {
        'normal' : {
            'txt' : "rgb(255,255,255)",
            'arrow':"rgb(0,0,0)",

        }
    };

I have tried below code in the javascript file, but I'm not getting the right output. Also, I don't know how to debug this.

var arrowcolor = document.getElementById('styles').innerHTML
    this.colours = {
        'normal' : {
            'txt' : "rgb(255,255,255)",
            'arrow':"'+arrowcolor+'",
        }
    };
Elias
  • 17
  • 2
  • 1
    Does this answer your question? [How do I get the value of text input field using JavaScript?](https://stackoverflow.com/questions/11563638/how-do-i-get-the-value-of-text-input-field-using-javascript) – Kalimah Dec 02 '19 at 13:17
  • 1
    `var arrowcolor = document.getElementById('styles').value` would be more appropriate or `'arrow':document.getElementById('styles').value` – Professor Abronsius Dec 02 '19 at 13:17
  • You can use document.getElementById('styles').value; if you want to debug JS, simply put debugger; keyword in your javascript code and keep developer tools open. This would create a break point and you will be able to debug any js file easily. – Durgesh Dec 02 '19 at 13:29
  • oh, btw you need to set the ID on the element – Professor Abronsius Dec 02 '19 at 13:46

1 Answers1

0

Use value instead of innerHTML

var arrowcolor = document.getElementById('styles').value
    this.colours = {
        'normal' : {
            'txt' : "rgb(255,255,255)",
            'arrow':arrowcolor,
        }
    };
Nilesh Daldra
  • 69
  • 1
  • 9
Pushprajsinh Chudasama
  • 7,772
  • 4
  • 20
  • 43