Reputation: 231
I am confused on a task I have been given:
Function: takes 2 parameters, a string and a label id and writes the string value to the text of the label
• Example:
changeLabel('mylabel1', ‘label1’);
should change the text value of
‘<label id="label1">Form Label1</label>’
to
‘<label id="label1">mylabel1</label>’
I am not sure where to put the variables which need to be passed in, here is my code but it will not validate when it is tested.
function changeLabel('mylabel1', 'label1'){
document.getElementById("label1").innerHTML = mylabel1;
}
changeLabel('mylabel1', 'label1');
Can someone please help?
Upvotes: 0
Views: 27
Reputation: 5953
You can't define function with strings
as parameters
. you should do it like this:
function changeLabel(text, id){
document.getElementById(id).innerHTML = text;
}
changeLabel('mylabel1', 'label1');
Upvotes: 3