how to return a value to a document.getElementById()
Posted: Wed Jan 28, 2009 12:24 am
pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:
Posting Code in the Forums to learn how to do it too.
Hi all..what i'm trying to do is change the backgroundColor of my input text with js..
this the js part
and this is the html part
basicly what the script do is to check the hidden field cf with value of '0' if found it will execute changeCssProp(thefield)..but the problem is js return
error of document.getElementById(thefield) is null
can someone help me with..thanking you all in advance for reviewing my
pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:
Posting Code in the Forums to learn how to do it too.
Hi all..what i'm trying to do is change the backgroundColor of my input text with js..
this the js part
Code: Select all
function CreateCFormArray(){
var y=document.getElementsByName("cf");
//alert(y[0].value);
for(i = 0; i < y.length; i++) {
if(y[i].id=='cf1' && y[i].value=='0'){
changeCssProp(name);
}
if(y[i].id=='cf2' && y[i].value=='0'){
changeCssProp(phone);
}
}
}
var thefield;
function changeCssProp(thefield) {
document.getElementById(thefield).style.backgroundColor="#FF0000";
}
Code: Select all
<form id="form1" name="form1" method="post" action="">
<table width="100%" border="2" cellspacing="0" cellpadding="0">
<tr>
<td>name</td>
<td>
<label>
<input type="text" name="name" id="name" />
</label>
</td>
<td> </td>
</tr>
<tr>
<td>phone</td>
<td>
<label>
<input type="text" name="phone" id="phone" />
</label>
</td>
<td> </td>
</tr>
<tr>
<td>
<label>
<input type="button" name="Submit" value="Submit" onclick="CreateCFormArray()" />
</label>
</td>
<td>
<input name="cf" type="hidden" id="cf1" value="0" />
<input name="cf" type="hidden" id="cf2" value="0" />
</td>
<td> </td>
</tr>
</table>
</form>
error of document.getElementById(thefield) is null
can someone help me with..thanking you all in advance for reviewing my
pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: