VBScript question (Full Version)

All Forums >> [Web Development] >> ASP and Database



Message


sarge -> VBScript question (1/10/2002 10:22:26)

Hi-
I have a page with some checkboxes which, when clicked, alter the characteristics of a table, and I'm doing this with VBScript.
For example, if I want to flip-flop a border around the table, I do:
Select case window.event.srcElement.id
Case "boxed"
if mytable.border = "4" then
mytable.border = "0"
else
mytable.border = "4"
end if
This works fine. The problem is that I can't find the right syntax to do the same with bgcolor. If I do:
Case "bright"
if mytable.bgcolor = "#FFFF66" then
mytable.bgcolor = "#FFFFCC"
else
mytable.bgcolor = "#FFFF66"
end if
It always takes the else path, and I can't find any syntax that gets recognised (even though the browser recognises the else value when it gets inserted).

Any ideas?
Thanks, Sarge



 




ginnie -> RE: VBScript question (1/10/2002 11:51:45)

I believe that should be "background-color".



ginnie
Global Presence Web Design




sarge -> RE: VBScript question (1/10/2002 12:46:44)

Hi Ginnie-
I've tried using background-color, but I just get 'Error on page' at run time. I've also tried the syntax "(##FFFF66)", but still no joy.

 




ginnie -> RE: VBScript question (1/10/2002 12:57:35)

Do you have a url?

Or can you post the entire code?

ginnie
Global Presence Web Design




sarge -> RE: VBScript question (1/10/2002 18:24:04)

Hi Ginnie-

These are the relevant bits of HTML, extracted from the page.
(The page itself is rather large)

1.) This is the SCRIPT

<SCRIPT language="VBSCRIPT">
sub document_onclick
Select case window.event.srcElement.id
Case "boxed"
if histable.border = "4" then
histable.border = "0"
else
histable.border = "4"
end if
Case "bright"
if histable.background-color = "#FFFF66" then
histable.background-color = "#FFFFCC"
else
histable.background-color = "#FFFF66"
end if
Case else
exit sub
End select
end sub
</SCRIPT>

2.) This is the table 'histable':

<table id=histable width="100%" border="<%If FP_FieldVal(fp_rs,"trad_boxed")= "True" then response.write "4" else response.write "0"%>" cellspacing="0" cellpadding="3" height="20" style="background-color: <%If FP_FieldVal(fp_rs,"trad_bright")= "True" then response.write "#FFFF66" else response.write "#FFFFCC"%>" >

3.) These are the checkboxes:

<input id=boxed type="<%If FP_FieldVal(fp_rs,"trad_boxed")= "True" then response.write "hidden" else response.write "checkbox"%>" name="boxed" value="ON" <%If FP_FieldURL(fp_rs,"trad_boxed") = "True" then response.write " checked"%>>

<input id=bright type="<%If FP_FieldVal(fp_rs,"trad_bright")= "True" then response.write "hidden" else response.write "checkbox"%>" name="bright" value="ON" <%If FP_FieldURL(fp_rs,"trad_bright") = "True" then response.write " checked"%>>

------------------------------------
Just in case you're wondering, the object of the page is this:
The site has a directory of computer traders in London, and this page allows traders to 'play with' the way that their details are presented. Its a bit like yellow pages (where you can box entries, change the font size, the background color etc.). Checkboxes get hidden when the trader takes up an option (for a year).
------------------------------------

Anyway, thanks in advance,
Sarge

 




ginnie -> RE: VBScript question (1/10/2002 21:36:30)

Hmmm...I don't know. I've not done any scripting that changes styles. My only other suggestion would be to try bgColor.

Note: I'm moving this thread to the database forum where the VB Scripters hang out.

ginnie
Global Presence Web Design




sarge -> RE: VBScript question (1/10/2002 22:32:22)

Thanks Ginnie-
I tried bgcolor. It doesn't give an error, but it doesn't seem to recognise syntax like:

if histable.bgcolor = "#FFFFCC" then...

It always takes the 'not equal' path.

Why is syntax such a pain? With a bit more programming effort, I'm sure that many languages could be much more accommodating without being inaccurate. This exercise should be sooo easy...
Anyway, if I can't find the answer, I'll have to resort to DIVs & layers & visibilities & things. And that really will be a pain.

 




Mojo -> RE: VBScript question (1/11/2002 0:25:10)

If I understand what your after, the following works. I did not use a style in the table, just bgColor="#000066" (which you can change dynamically). The else statement is NOT chosen because the If is true. This is easily shown by the message box not popping up or you could change the table bgColor to something else besides #000066.

Here goes:

<table id=histable width="100%" bgColor="#000066">
<tr>
<td>Chicago</td>
</tr>
</table>
<SCRIPT language="VBSCRIPT">

If histable.bgColor = "#000066" Then
histable.bgColor = "#cccccc"
Else
myColor = histable.bgColor
alert(mycolor)
histable.bgColor = "red"
End If

</SCRIPT>


Joe





sarge -> RE: VBScript question (1/11/2002 10:00:23)

Hi Joe-

Its working. I've finally found out what was happening. And I'm gobsmacked.

I was doing:
if histable.bgcolor = "#FFFFCC"
I should have been doing:
if histable.bgcolor = "#ffffcc"

Although FP represents the hex values in upper case in the HTML, they seem to get surreptitiously converted to lower case somewhere along the way.

Anyway, many thanks for your help. It was only by making liberal use of your alert boxes that I spotted it. Perhaps I should buy a book on VBScript.
Or maybe I should be put out to grass...

Regards,
Sarge


 




Mojo -> RE: VBScript question (1/11/2002 10:33:01)

Glad you got it!





ginnie -> RE: VBScript question (1/11/2002 10:39:33)

When I recommended byColor, I was referring to the upper case "C" instead of just "bgcolor". I remember that in JavaScript, it had to be an upper case C.

Glad you got it working though.

Edit: Just curious for future reference, in your working version, are you using bgcolor (like you originally used) or bgColor (as shown in Joe's example)?

ginnie
Global Presence Web Design

Edited by - ginnie on 01/11/2002 11:43:10




sarge -> RE: VBScript question (1/11/2002 11:20:15)

Could I ask you another 'quickie'?
I now need to do the same sort of thing with font size and font color. Can these be changed dynamically? I'm not having much luck so far...
Thanks,
Sarge

 




sarge -> RE: VBScript question (1/11/2002 13:14:39)

Skip that. Style works.
e.g. hisname.style.color = "#708090"

Amen. (I hope)

 




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
8.984375E-02