I am trying to write a program with several text fields and 1 button. When the user clicks the button, the value for the text fields changes to how are you.
I'm not sure how to refer to a value ifor an expressiondocument.getElementById('text'+i).value= 'how are you'
<input name="text1" type="text" id="text1" value="textbox 1"
onFocus="this.style.background ='yellow'" onBlur="this.style.background='white'">
<input name="text2" type="text" id="text2" value="textbox 2"
onFocus="this.style.background = 'yellow'" onBlur="this.style.background='white'">
function popup() {
for( int i; i <2, i++) {
document.getElementById('text'+i).value= 'how are you'
}
}
<input type="button" value="Click Me!" onclick="popup()"><br />
I changed part of the for loop, but still not quite working:
function popup() {
for( var i = 1, i <= 2, i++) {
document.getElementById('text'+i).value= 'how are you'
}
}
Will the program work with the foreach loop, as in C ++? First, it will count the number of text fields that you have, and then create a list that goes from 1 to the total number of text fields, then write a for loop to count the text fields.
source
share