Click to See Complete Forum and Search --> : Changing form field properties


davidcholley
01-24-2003, 10:03 PM
Hello, I'm in the process of implementing form field validation. In the past, I've done this with VBScript and would now like to migrate to JavaScript. Posted below is the syntax that I'm trying to use to alter the appearance of the fields on the form. Can anyone help me out as to why it fails in JavaScript? The problem (I assume) lays with how I'm trying to reference the field properties. I'm confused through because it seems to work fine with VBScript. (Unless of course MS decided to go off on their own - again.)

function btnSubmit_onClick()
{
document.frmInformationRequest.userName.value = "Test"
document.frmInformationRequest.userName.style.color = #FFFFFF
document.frmInformationRequest.userName.style.backgroundcolor = #FF0000
}

khalidali63
01-24-2003, 10:11 PM
the pattern to reference a form elements is as follows.

document.formName.elementName.attributeName

your code is almost there.
document.frmInformationRequest.userName.value = "Test"
the above should work if the
form name = frmInformationRequest
and element name = userName

document.frmInformationRequest.userName.style.color = "#FFFFFF"
notice the qoutes around value
document.frmInformationRequest.userName.style.backgroundcolor = "#FF0000 "
qoutes and the css property backgroundcolor is referenced in JavaScript as
backgroundColor = "Color"

hope this helps

cheers

Khalid

davidcholley
01-24-2003, 10:48 PM
(Banging head up against wall...) But that's EXACTLY how it appeared in a VBScript function and it didn't work when I copied it???!!!

thx

David

P.S.
If you didn't pick up on it, the point is to highlight fields that need to be corrected. Hmmm...sounds like somethings that should apear as a sample here.

davidcholley
01-24-2003, 10:59 PM
Speaking to soon, I assumed that the following would work to change the font to BOLD as well...

function btnSubmit_onClick()
{
document.frmInformationRequest.userName.style.fontweight = "bold"

document.frmInformationRequest.userName.style.backgroundColor = "#FF0000"

document.frmInformationRequest.userName.style.color = "#FFFFFF"

}

...but it doesn't...


GRRRR.....

khalidali63
01-25-2003, 12:48 AM
style.fontWeight = "bold"

should do it.

davidcholley
01-25-2003, 08:59 AM
But of course it does since the property is fontWeight as opposed to fontweight.