Good morning,

I am a newly self made vbscript developper.
I am developping a web based access data collection system and I need to
change the background color of the text label whenever a field is set to
empty by deleting the content.
For instance:
document.getElementById("Tickets_OrderNu").value= ????

I tried empty, blank, null, nothing.

No success up to now. Is this posiible?
Maybe .value is not the right keyword, should I use another one?

Thanks

Gilles

--
GillesABelanger

Re: Identifying an empty field to change the backgorund color of the t by deckhopper

deckhopper
Tue Jan 24 00:59:38 CST 2006

Try this:

document.getElementById("Tickets_OrderNu").value = ""

Referred to as an "empty string" --> two double-quotes with NO space in
between them.


Re: Identifying an empty field to change the backgorund color of t by GillesABelanger

GillesABelanger
Thu Jan 26 09:36:02 CST 2006

Using "" is not working. Is there any other method to reflect a cleared field?
--
GillesABelanger


"deckhopper" wrote:

> Try this:
>
> document.getElementById("Tickets_OrderNu").value = ""
>
> Referred to as an "empty string" --> two double-quotes with NO space in
> between them.
>
>

Re: Identifying an empty field to change the backgorund color of t by Bob

Bob
Thu Jan 26 10:07:40 CST 2006

Please post the html of a small repro page where this does not work. Start
with:

<HTML>
<HEAD>
<SCRIPT type="text/vbscript" LANGUAGE="vbscript">
sub btnchange_onclick()
dim input
set input=document.getElementById("Tickets_OrderNu")
if input.value="" then
input.style.backgroundcolor="silver"
else
input.style.backgroundcolor="yellow"
end if
end sub
</SCRIPT>
</HEAD>
<BODY>
<INPUT id="Tickets_OrderNu" type="text" value=""
style="background-color:silver">
<INPUT type="button" id="btnChange" value="Change Color">
</BODY>
</HTML>

Show us how to reproduce your problem

Bob Barrows
GillesABelanger wrote:
> Using "" is not working. Is there any other method to reflect a
> cleared field? --
> GillesABelanger
>
>
> "deckhopper" wrote:
>
>> Try this:
>>
>> document.getElementById("Tickets_OrderNu").value = ""
>>
>> Referred to as an "empty string" --> two double-quotes with NO space
>> in between them.

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.



Re: Identifying an empty field to change the backgorund color of t by GillesABelanger

GillesABelanger
Thu Jan 26 10:51:05 CST 2006

Good morning,

Here is exactly what I have:
<SCRIPT language=vbscript event=onchange for=Tickets_OrderNu>
<!--
if document.getElementById("Tickets_OrderNu").value<>0 then
CICODE.disabled= False
Quantity.disabled= False
document.getElementById("Tickets_OrderNu_Label").style.backgroundcolor=RGB(0,&HFF,0)
document.getElementById("CICODE_Label").style.backgroundcolor=RGB(0,&HFF,0)
document.getElementById("Quantity_Label").style.backgroundcolor=RGB(0,&HFF,0)
document.getElementById("CICODE").style.backgroundcolor=RGB(255,255,255)
document.getElementById("Quantity").style.backgroundcolor=RGB(255,255,255)
MsgBox "You need to enter values in the next two fields below, CICODE and
Quantity for this CICODE.",48, "Data entry rules."
Elseif document.getElementById("Tickets_OrderNu").value="" or _
document.getElementById("Tickets_OrderNu").value=0 then
CICODE.disabled= True
Quantity.disabled= True
document.getElementById("Tickets_OrderNu_Label").style.backgroundcolor=RGB(192,192,192)
document.getElementById("Quantity_Label").style.backgroundcolor=RGB(255,255,255)
document.getElementById("CIcode").style.backgroundcolor=RGB(230,230,230)
document.getElementById("Quantity").style.backgroundcolor=RGB(230,230,230)
End if

Everything works except the line where the .value=""

I am new at vbscript and I do not see the difference between your approach
which is to declare a variable and this approach which is to compare the
value directly to "". Please help me to understand.

Thanks

--
GillesABelanger


"Bob Barrows [MVP]" wrote:

> Please post the html of a small repro page where this does not work. Start
> with:
>
> <HTML>
> <HEAD>
> <SCRIPT type="text/vbscript" LANGUAGE="vbscript">
> sub btnchange_onclick()
> dim input
> set input=document.getElementById("Tickets_OrderNu")
> if input.value="" then
> input.style.backgroundcolor="silver"
> else
> input.style.backgroundcolor="yellow"
> end if
> end sub
> </SCRIPT>
> </HEAD>
> <BODY>
> <INPUT id="Tickets_OrderNu" type="text" value=""
> style="background-color:silver">
> <INPUT type="button" id="btnChange" value="Change Color">
> </BODY>
> </HTML>
>
> Show us how to reproduce your problem
>
> Bob Barrows
> GillesABelanger wrote:
> > Using "" is not working. Is there any other method to reflect a
> > cleared field? --
> > GillesABelanger
> >
> >
> > "deckhopper" wrote:
> >
> >> Try this:
> >>
> >> document.getElementById("Tickets_OrderNu").value = ""
> >>
> >> Referred to as an "empty string" --> two double-quotes with NO space
> >> in between them.
>
> --
> Microsoft MVP -- ASP/ASP.NET
> Please reply to the newsgroup. The email account listed in my From
> header is my spam trap, so I don't check it very often. You will get a
> quicker response by posting to the newsgroup.
>
>
>

Re: Identifying an empty field to change the backgorund color of t by deckhopper

deckhopper
Thu Jan 26 14:06:53 CST 2006

Leave the field blank and try this:

Msgbox document.getElementById("Tickets_OrderNu").value
Msgbox VarType(document.getElementById("Tickets_OrderNu").value)

This will tell you what the value is and what type of value (lookup
VarType Constants). Also do what Bob Barrows asked with a sample page.
Your snippet of code isn't enough.


Re: Identifying an empty field to change the backgorund color of t by Bob

Bob
Thu Jan 26 14:31:40 CST 2006

GillesABelanger wrote:
> Good morning,
>
> Here is exactly what I have:
:-)
I did not want to see exactly what you have. I only wanted to see the bare
minimum needed to reproduce your problem.

> <SCRIPT language=vbscript event=onchange for=Tickets_OrderNu>
> <!--
> if document.getElementById("Tickets_OrderNu").value<>0 then

I suspect this line will never return true. The value property will contain
a string, not a number. You should be comparing to "0", not 0.

I think you should rearrange your logic so that the first thing you check
for is "". Then check for different values in subsequent if statements

<snip>
> Everything works except the line where the .value=""

>
> I am new at vbscript and I do not see the difference between your
> approach which is to declare a variable and this approach which is to
> compare the value directly to "". Please help me to understand.

It is bad practice (wastes CPU and resources) to make multiple calls to
GetElementByID when a single call will do. That is why I set a variable to
the result of the call and use it. You should adopt this practice.

Of course, that has nothing to do with your problem, which I have yet to see
how to reproduce. Create a page using the sample code I provided and either
add whatever it takes to reproduce your problem and explain to us how to
make it happen. The idea is to eliminate everything from the page that has
nothing to do with reproducing your problem so we can focus on it.

Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.



Re: Identifying an empty field to change the backgorund color of t by Bob

Bob
Thu Jan 26 14:58:21 CST 2006

Bob Barrows [MVP] wrote:
>> if document.getElementById("Tickets_OrderNu").value<>0 then
>
> I suspect this line will never return true.

My suspicion was incorrect. An implicit conversion occurs so 0 is converted
to a string before comparing it to value.
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.



Re: Identifying an empty field to change the backgorund color of t by Bob

Bob
Thu Jan 26 15:10:03 CST 2006

Bob Barrows [MVP] wrote:
> Bob Barrows [MVP] wrote:
>>> if document.getElementById("Tickets_OrderNu").value<>0 then
>>
>> I suspect this line will never return true.
>
> My suspicion was incorrect. An implicit conversion occurs so 0 is
> converted to a string before comparing it to value.

Do this:
<HTML>
<HEAD>
<SCRIPT type="text/vbscript" LANGUAGE="vbscript">
sub btnchange_onclick()
dim input

set input=document.getElementById("Tickets_OrderNu")
if input.value="" then
input.style.backgroundcolor="red"
elseif input.value="0" then
input.style.backgroundcolor="silver"
elseif input.value<>"0" then
input.style.backgroundcolor="yellow"
end if
end sub
</SCRIPT>
</HEAD>
<BODY>
<INPUT id="Tickets_OrderNu" type="text" value=""
style="background-color:silver">
<INPUT type="button" id="btnChange" value="Change Color">
</BODY>
</HTML>


.Bob Barrows

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.



Re: Identifying an empty field to change the backgorund color of t by GillesABelanger

GillesABelanger
Fri Jan 27 05:20:02 CST 2006

Good morning Bob,

By declaring documentGetElementByID("Tickets_OrderNu").value a variable, it
is working!

Thanks a lot, you are making my day.
--
GillesABelanger


"Bob Barrows [MVP]" wrote:

> Bob Barrows [MVP] wrote:
> > Bob Barrows [MVP] wrote:
> >>> if document.getElementById("Tickets_OrderNu").value<>0 then
> >>
> >> I suspect this line will never return true.
> >
> > My suspicion was incorrect. An implicit conversion occurs so 0 is
> > converted to a string before comparing it to value.
>
> Do this:
> <HTML>
> <HEAD>
> <SCRIPT type="text/vbscript" LANGUAGE="vbscript">
> sub btnchange_onclick()
> dim input
>
> set input=document.getElementById("Tickets_OrderNu")
> if input.value="" then
> input.style.backgroundcolor="red"
> elseif input.value="0" then
> input.style.backgroundcolor="silver"
> elseif input.value<>"0" then
> input.style.backgroundcolor="yellow"
> end if
> end sub
> </SCRIPT>
> </HEAD>
> <BODY>
> <INPUT id="Tickets_OrderNu" type="text" value=""
> style="background-color:silver">
> <INPUT type="button" id="btnChange" value="Change Color">
> </BODY>
> </HTML>
>
>
> ..Bob Barrows
>
> --
> Microsoft MVP -- ASP/ASP.NET
> Please reply to the newsgroup. The email account listed in my From
> header is my spam trap, so I don't check it very often. You will get a
> quicker response by posting to the newsgroup.
>
>
>