Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing color of text box

Status
Not open for further replies.

vedicman

Programmer
Sep 5, 2003
128
0
0
US
I need to change the background color of an asp.net textbox every 15 seconds. Can anyone please provide a detailed code sample of how to accomplish this?

Thank You.....Franco
 
You'll have to do this in JavaScript by using a Timer...


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Thanks ca8msm

I have java script code to do just that. Can you give me a DETAILED sample of how to weave java script into the vb.net code on an asp.net page? I've never had to do that prior to this.

Thanks.....Franco
 
It's exactly the same as if it were a HTML page. Insert your script into the HTML document, and call the function on the body onload event.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
like ca8msm said, ur JS will NOT interact with the .NET coding...

Known is handfull, Unknown is worldfull
 
ca8msm & vbkris

I pasted my java script into the aspx page and I'm getting the following message when I attempt to open it:

Cannot use 'JavaScript' because another language has been specified earlier in this page.

Can you provide a sample of using java script with VB.net in the same aspx?

Thank You...Franco
 
sure, which version of .NET are u using?

Known is handfull, Unknown is worldfull
 
Just paste it into the <head> section e.g.
Code:
<head runat="server">
    <title>Untitled Page</title>
    <script type="text/javascript">
        function testFunction()
        {
            document.getElementById("TextBox1").value = 'hello';
        }
    </script>
</head>


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Here is the whole page which I developed in notepad. Please see below at which point I need to RUN THE JAVA SCRIPT code:

Thank You

*******************
<%@ Page Language= "VB" debug="true" SmartNavigation="true" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDB" %>
<%@ Import Namespace="System.Data.SQLClient" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Drawing" %>

<Script Language="VB" runat="Server">

''**************************************************************
Sub Page_Load(s as object, e as eventArgs)

Dim i as integer

If Not Page.IsPostback Then
For i = 1 to 12
ddlMonths.Items.Add( i )
Next i

For i = 1 to 31
ddlDays.Items.Add( i )
Next i

For i = 1940 to 2010
ddlYears.Items.Add( i )
Next i

For i = 1 to 12
ddlHour.Items.Add( i )
Next i

For i = 0 to 59
ddlMin.Items.Add( i )
Next i

ddlAMPM.Items.Add("AM")
ddlAMPM.Items.Add("PM")

End If

If Page.IsPostBack Then
Get1stColor()
End If

End Sub
'**************************************************************
Sub Get1stColor()

Dim iWeekday As Integer
Dim s1st As String
Dim sRemain As String
Dim sDate as string

sDate = ddlmonths.SelectedItem.value + "/" + ddldays.SelectedItem.value + "/" + ddlyears.SelectedItem.value
iWeekday = Weekday(sDate)

Select Case iWeekday
Case 1
s1st = "G"
sRemain = "FEDCBA"
Case 2
s1st = "F"
sRemain = "EDCBAG"
Case 3
s1st = "E"
sRemain = "DCBAGF"
Case 4
s1st = "D"
sRemain = "CBAGFE"
Case 5
s1st = "C"
sRemain = "BAGFED"
Case 6
s1st = "B"
sRemain = "AGFEDC"
Case 7
s1st = "A"
sRemain = "GFEDCB"
End Select

Call Get2ndColor(s1st, sRemain)

End Sub
'**************************************************************
Sub Get2ndColor(s1st As String, sRemain As String)

Dim iAMPM As Integer
Dim sAMPM as string
Dim iHr As Integer
Dim iMin As Integer
Dim iMinTotal As Integer
Dim s2nd As String
Dim sMyColors As String
Dim iMinRemain As Integer

If ddlHour.SelectedItem.value = 12 and ddlAMPM.SelectedItem.value = "AM" then
iHr = 0
Else
iHr = ddlHour.SelectedItem.value
End If
iMin = ddlMin.SelectedItem.value
sAMPM = ddlAMPM.SelectedItem.value
If sAMPM = "AM" Then iAMPM = 0
If sAMPM = "PM" Then iAMPM = 720
iMinTotal = iAMPM + (iHr * 60) + iMin

Select Case iMinTotal
Case Is < 240
s2nd = Mid(sRemain, 1, 1)
sRemain = Mid(sRemain, 2, 5)
Case 240 To 479
s2nd = Mid(sRemain, 2, 1)
sRemain = Mid(sRemain, 3, 4) & Mid(sRemain, 1, 1)
Case 480 To 719
s2nd = Mid(sRemain, 3, 1)
sRemain = Mid(sRemain, 4, 3) & Mid(sRemain, 1, 2)
Case 720 To 959
s2nd = Mid(sRemain, 4, 1)
sRemain = Mid(sRemain, 5, 2) & Mid(sRemain, 1, 3)
Case 960 To 1199
s2nd = Mid(sRemain, 5, 1)
sRemain = Mid(sRemain, 6, 1) & Mid(sRemain, 1, 4)
Case 1200 To 1439
s2nd = Mid(sRemain, 6, 1)
sRemain = Mid(sRemain, 1, 5)
End Select

sMyColors = s1st & s2nd
iMinRemain = iMinTotal Mod 240

Call Get3rdColor(iMinRemain, sMyColors, sRemain)

End Sub
'**************************************************************
Sub Get3rdColor(iMinRemain As Integer, sMyColors As String, sRemain As String)

Dim s3rd As String

Select Case iMinRemain
Case Is < 48
s3rd = Mid(sRemain, 1, 1)
sRemain = Mid(sRemain, 2, 4)
Case 48 To 95
s3rd = Mid(sRemain, 2, 1)
sRemain = Mid(sRemain, 3, 3) & Mid(sRemain, 1, 1)
Case 96 To 143
s3rd = Mid(sRemain, 3, 1)
sRemain = Mid(sRemain, 4, 2) & Mid(sRemain, 1, 2)
Case 144 To 191
s3rd = Mid(sRemain, 4, 1)
sRemain = Mid(sRemain, 5, 1) & Mid(sRemain, 1, 3)
Case 192 To 239
s3rd = Mid(sRemain, 5, 1)
sRemain = Mid(sRemain, 1, 4)
End Select

sMyColors = sMyColors & s3rd
iMinRemain = iMinRemain Mod 48

Call Get4thColor(iMinRemain, sMyColors, sRemain)

End Sub
'**************************************************************
Sub Get4thColor(iMinRemain As Integer, sMyColors As String, sRemain As String)

Dim s4th As String

Select Case iMinRemain
Case Is < 12
s4th = Mid(sRemain, 1, 1)
sRemain = Mid(sRemain, 2, 3)
Case 12 To 23
s4th = Mid(sRemain, 2, 1)
sRemain = Mid(sRemain, 3, 2) & Mid(sRemain, 1, 1)
Case 24 To 35
s4th = Mid(sRemain, 3, 1)
sRemain = Mid(sRemain, 4, 1) & Mid(sRemain, 1, 2)
Case 36 To 47
s4th = Mid(sRemain, 4, 1)
sRemain = Mid(sRemain, 1, 3)
End Select

sMyColors = sMyColors & s4th
iMinRemain = iMinRemain Mod 12

Call Get5thColor(iMinRemain, sMyColors, sRemain)

End Sub
'**************************************************************
Sub Get5thColor(iMinRemain As Integer, sMyColors As String, sRemain As String)

Dim s5th As String

Select Case iMinRemain
Case Is < 4
s5th = Mid(sRemain, 1, 1)
sRemain = Mid(sRemain, 2, 2)
Case 4 To 7
s5th = Mid(sRemain, 2, 1)
sRemain = Mid(sRemain, 3, 1) & Mid(sRemain, 1, 1)
Case 8 To 11
s5th = Mid(sRemain, 3, 1)
sRemain = Mid(sRemain, 1, 2)
End Select

sMyColors = sMyColors & s5th
iMinRemain = iMinRemain Mod 4

Call Get6and7thColors(iMinRemain, sMyColors, sRemain)

End Sub
'**************************************************************
Sub Get6and7thColors(iMinRemain As Integer, sMyColors As String, sRemain As String)

Dim s6th As String

Select Case iMinRemain
Case Is < 2
s6th = Mid(sRemain, 1, 1)
sRemain = Mid(sRemain, 2, 1)
Case 2 To 3
s6th = Mid(sRemain, 2, 1)
sRemain = Mid(sRemain, 1, 1)
End Select

sMyColors = sMyColors & s6th & sRemain

txtSequence.visible = "true"
txtSequence.text = sMyColors

Call ShowColors(sMyColors)

End Sub
'**************************************************************
Sub ShowColors(sMyColors as string)

Dim sColor(6) as string
Dim i as integer
Dim Color as string
Dim txtColors as textBox
'Dim sLetter as string

sColor(0) = Left(sMyColors,1)
sColor(1) = Mid(sMyColors,2,1)
sColor(2) = Mid(sMyColors,3,1)
sColor(3) = Mid(sMyColors,4,1)
sColor(4) = Mid(sMyColors,5,1)
sColor(5) = Mid(sMyColors,6,1)
sColor(6) = Mid(sMyColors,7,1)

For i = 0 to 6
Select case sColor(i)
Case "G"
Color = "purple"
Case "F"
Color = "blueviolet"
Case "E"
Color = "blue"
Case "D"
Color = "green"
Case "C"
Color = "yellow"
Case "B"
Color = "orange"
Case "A"
Color = "red"
End Select

txtColors = CType(FindControl("txt" & i+1), TextBox)
txtColors.backcolor = ColorTranslator.FromHtml(Color)

Next i

'RUN JAVA SCRIPT HERE
End Sub
'**************************************************************
</script>

<html>
<head>

<script language = "JavaScript">

var theTimeout;
var colorString;
var strColor;
var sFont;
var intNum = 0;
var intSecs;
var intTotalSecs;
var index;

function window_onload( )
{
enterColorString( )
}

function enterColorString( )
{
//colorString = "CGFDEAB";
colorString = txtSequence.text
intSecs = prompt("How many seconds between color changes?", "5");
intTotalSecs = parseInt(intSecs) * 1000
upDate( );
}

function getColors( )
{
strColor = new Array(colorString.substring(0,1), colorString.substring(1,2), colorString.substring(2,3), colorString.substring(3,4),
colorString.substring(4,5), colorString.substring(5,6), colorString.substring(6,7))

for (index = 0; index <7; index++)
{
switch (strColor[index])
{
case "G":
strColor[index] = "purple";
break;
case "F":
strColor[index] = "blueviolet";
break;
case "E":
strColor[index] = "blue";
break;
case "D":
strColor[index] = "green";
break;
case "C":
strColor[index] = "yellow";
break;
case "B":
strColor[index] = "orange";
break;
case "A":
strColor[index] = "red";
break;
}
}
}

function upDate()
{
var theNumber = intNum;
var theNumberLoop = (theNumber % 7) + 1;

theNumber = parseInt(theNumber) + 1;
intNum = theNumber;
//window.document.theForm.theText.value = theNumber;
theTimeout = setTimeout("upDate();", intTotalSecs)

getColors();

switch (theNumberLoop)
{
case 1:
document.bgColor = strColor[0];
lbl1.innerText="I'm having the time of my life!";
break;
case 2:
document.bgColor = strColor[1];
lbl1.innerText="No worries on my mind!";
break;
case 3:
document.bgColor = strColor[2];
lbl1.innerText="Everything is just fine!";
break;
case 4:
document.bgColor = strColor[3];
lbl1.innerText="Today is even better than yesterday!";
break;
case 5:
document.bgColor = strColor[4];
lbl1.innerText="Everything is going my way!";
break;
case 6:
document.bgColor = strColor[5];
lbl1.innerText="I'm living in the big time!";
break;
case 7:
document.bgColor = strColor[6];
lbl1.innerText="Generating my daily income is surprisingly fun & easy!";
break;
}
}
</script>

<style type="text/css">
.mytable
{ font-family:sans-serif;
font-size:8pt;
color:black; }
</style>
</head>
<body>

<form runat='server'>
<table>
<tr>
<td width='50'><ASP:label ID='lblmonths' text='Month' font-bold='true' runat='server' /></td>
<td width='50'><ASP:label ID='lbldays' text='Day' font-bold='true' runat='server' /></td>
<td width='50'><ASP:label ID='lblyears' text='Year' font-bold='true' runat='server' /></td>
</tr>
<tr>
<td><ASP:DropDownList ID='ddlmonths' runat='server' /></td>
<td><ASP:DropDownList ID='ddldays' runat='server' />
<td><ASP:DropDownList ID='ddlyears' runat='server' /></td>
</tr>

<tr>
<td width='50'><ASP:label ID='lblHour' text='Hour' font-bold='true' runat='server' /></td>
<td width='50'><ASP:label ID='lblMin' text='Min' font-bold='true' runat='server' /></td>
<td width='50'><ASP:label ID='lblAMPM' text='AM/PM' font-bold='true' runat='server' /></td>
</tr>
<tr>
<td><ASP:DropDownList ID='ddlHour' runat='server' /></td>
<td><ASP:DropDownList ID='ddlMin' runat='server' />
<td><ASP:DropDownList ID='ddlAMPM' runat='server' /></td>
</tr>
</table><br>

<ASP:button width='100' Id='btnSequence' on_click='Get1stColor' Text='Get Sequence' font-bold='true' runat='server' /><br><br><br>

<asp:TextBox
id='txtSequence'
visible = 'false'
font-size='12pt'
font-bold='true'
width = '90'
Runat='Server'/><br>

<table>
<tr>
<td>
<asp:TextBox Id='txt1' width='50' height='50' runat='server' />
</td>
<td>
<asp:TextBox Id='txt2' width='50' height='50' runat='server' />
</td>
<td>
<asp:TextBox Id='txt3' width='50' height='50' runat='server' />
</td>
<td>
<asp:TextBox Id='txt4' width='50' height='50' runat='server' />
</td>
<td>
<asp:TextBox Id='txt5' width='50' height='50' runat='server' />
</td>
<td>
<asp:TextBox Id='txt6' width='50' height='50' runat='server' />
</td>
<td>
<asp:TextBox Id='txt7' width='50' height='50' runat='server' />
</td>
</tr>
</table><br>

<asp:hyperlink ID='hlnkRunColors'
NavigateURL = ' text = 'Run Color Sequence'
font-size = '10pt'
runat='server' />

<asp:label ID = 'lblMsg'
Runat='Server'/>

</form>
</body>
</html>
*****************************************
 
ca8msm:
>> document.getElementById("TextBox1").value = 'hello';

would really depend upon the clientID of the textbox. it may not necessarily work in all situations, thats why i asked him the .NET version so that he can output the correct clietn Id to the JS file.

i usually use the Page.RegisterStartupScript to do it, if its .NET 2 then there is a different object to do this.


vedicman:
anyways where exactly have u called the function window_onload().
one more thing, could u give me a "view source" of the ASP.NET, that would be even better...

Known is handfull, Unknown is worldfull
 
ca8msm

All of the code is pasted above. What I'm trying to do here is to consolidate 2 pages into one. One page is an aspx that does some calculations. The second page is an html page with Java Script. The problem with that is that I must first run the aspx to do the calculations, then copy the results from a text box and hard code that into the java script.


I also have a link on my aspx that opens the html page, but agin I must first hard code into my java script to make it useful. Is there a way to pass in the contents of the asp.textbox to the java script on the html page? If so, that may be the easiset way to do it. If you know how to do that please show me how to do it.

Thanks....Franco
 
ca8msm:
>> document.getElementById("TextBox1").value = 'hello';

would really depend upon the clientID of the textbox. it may not necessarily work in all situations, thats why i asked him the .NET version so that he can output the correct clietn Id to the JS file.
It doesn't make a difference which version of the framework the poster is using with regards to the clientid and that was just an example of how to put a javascript function into a page (which is what the poster asked). I could have wrote anything in that function...


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
oh, the version is NOT for the ClientId, its for the command that will output the JS.

e.g.:
in .NET 1.1 we would use
Page.RegisterClientScript("ClientTxtObject","<script>theTxtBox=document.forms[0]." & txt1.clientID & "</script>")

in .NET 2 there is a special object for handling JS itself if i am correct. its only for this that i required the code.

ok, i will assume its .NET 1.1

e.g.:
Page.RegisterClientScript("ClientTxtObject","<script>theTxtBox=document.forms[0]." & txt1.clientID & ";setTimeout('changeColors()',15000)</script>")


in the ASPX file:
<script>
//Color array:
var addCol=new array()
arrCol[0]="red"
arrCol[1]="green"
var currentColor=0
function changeColors()
{
theTxtBox.style.bgColor=arrCol[currentColor]
currentColor++
if(currentColor>=arrCol.length)
currentColor=0

setTimeout('changeColors()',15000)
}
</script>


Known is handfull, Unknown is worldfull
 
The only difference between framework versions in this case is that RegisterClientScript has been moved to the ClientScript class (although Page.RegisterClientScript will still work) and is irrelevant in this case as the client id will always be the same.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
>>and is irrelevant in this case as the client id will always be the same

maybe, but again, i thought it was better to warn the poster regarding the same. cause it may not work in other situations, like the txtbox could be inside a datagrid (or) a usercontrol etc.

>>The only difference between framework versions in this case is that RegisterClientScript has been moved to the ClientScript class

bingo! i required that info so that i could give an example to the poster, thats all...

Known is handfull, Unknown is worldfull
 
Hello

I've have got it working more or less, but there is still a small glitch. The first color in the sequence displays briefly, then the backcolor goes white again, then the colors display in sequence for 5 seconds each as they are supposed to do. I will paste the entire code below, and I'm hoping that someone will paste it into notepad and give it an aspx extension and run it to experience the glitch noted above. Hopefully someone can then show me how to go straight into the color sequence without the initial glitch.

Thanks for helping thus far. Your insights are appreciated:

Here's the code:
*********************
<%@ Page Language= "VB" debug="true" SmartNavigation="true" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDB" %>
<%@ Import Namespace="System.Data.SQLClient" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Drawing" %>

<Script Language="VB" runat="Server">

''**************************************************************
Sub Page_Load(s as object, e as eventArgs)

Dim i as integer

If Not Page.IsPostback Then
For i = 1 to 12
ddlMonths.Items.Add( i )
Next i

For i = 1 to 31
ddlDays.Items.Add( i )
Next i

For i = 1940 to 2010
ddlYears.Items.Add( i )
Next i

For i = 1 to 12
ddlHour.Items.Add( i )
Next i

For i = 0 to 59
ddlMin.Items.Add( i )
Next i

ddlAMPM.Items.Add("AM")
ddlAMPM.Items.Add("PM")

End If

If Page.IsPostBack Then
Get1stColor()
End If

End Sub
'**************************************************************
Sub Get1stColor()

Dim iWeekday As Integer
Dim s1st As String
Dim sRemain As String
Dim sDate as string

sDate = ddlmonths.SelectedItem.value + "/" + ddldays.SelectedItem.value + "/" + ddlyears.SelectedItem.value
iWeekday = Weekday(sDate)

Select Case iWeekday
Case 1
s1st = "G"
sRemain = "FEDCBA"
Case 2
s1st = "F"
sRemain = "EDCBAG"
Case 3
s1st = "E"
sRemain = "DCBAGF"
Case 4
s1st = "D"
sRemain = "CBAGFE"
Case 5
s1st = "C"
sRemain = "BAGFED"
Case 6
s1st = "B"
sRemain = "AGFEDC"
Case 7
s1st = "A"
sRemain = "GFEDCB"
End Select

Call Get2ndColor(s1st, sRemain)

End Sub
'**************************************************************
Sub Get2ndColor(s1st As String, sRemain As String)

Dim iAMPM As Integer
Dim sAMPM as string
Dim iHr As Integer
Dim iMin As Integer
Dim iMinTotal As Integer
Dim s2nd As String
Dim sMyColors As String
Dim iMinRemain As Integer

If ddlHour.SelectedItem.value = 12 and ddlAMPM.SelectedItem.value = "AM" then
iHr = 0
Else
iHr = ddlHour.SelectedItem.value
End If
iMin = ddlMin.SelectedItem.value
sAMPM = ddlAMPM.SelectedItem.value
If sAMPM = "AM" Then iAMPM = 0
If sAMPM = "PM" Then iAMPM = 720
iMinTotal = iAMPM + (iHr * 60) + iMin

Select Case iMinTotal
Case Is < 240
s2nd = Mid(sRemain, 1, 1)
sRemain = Mid(sRemain, 2, 5)
Case 240 To 479
s2nd = Mid(sRemain, 2, 1)
sRemain = Mid(sRemain, 3, 4) & Mid(sRemain, 1, 1)
Case 480 To 719
s2nd = Mid(sRemain, 3, 1)
sRemain = Mid(sRemain, 4, 3) & Mid(sRemain, 1, 2)
Case 720 To 959
s2nd = Mid(sRemain, 4, 1)
sRemain = Mid(sRemain, 5, 2) & Mid(sRemain, 1, 3)
Case 960 To 1199
s2nd = Mid(sRemain, 5, 1)
sRemain = Mid(sRemain, 6, 1) & Mid(sRemain, 1, 4)
Case 1200 To 1439
s2nd = Mid(sRemain, 6, 1)
sRemain = Mid(sRemain, 1, 5)
End Select

sMyColors = s1st & s2nd
iMinRemain = iMinTotal Mod 240

Call Get3rdColor(iMinRemain, sMyColors, sRemain)

End Sub
'**************************************************************
Sub Get3rdColor(iMinRemain As Integer, sMyColors As String, sRemain As String)

Dim s3rd As String

Select Case iMinRemain
Case Is < 48
s3rd = Mid(sRemain, 1, 1)
sRemain = Mid(sRemain, 2, 4)
Case 48 To 95
s3rd = Mid(sRemain, 2, 1)
sRemain = Mid(sRemain, 3, 3) & Mid(sRemain, 1, 1)
Case 96 To 143
s3rd = Mid(sRemain, 3, 1)
sRemain = Mid(sRemain, 4, 2) & Mid(sRemain, 1, 2)
Case 144 To 191
s3rd = Mid(sRemain, 4, 1)
sRemain = Mid(sRemain, 5, 1) & Mid(sRemain, 1, 3)
Case 192 To 239
s3rd = Mid(sRemain, 5, 1)
sRemain = Mid(sRemain, 1, 4)
End Select

sMyColors = sMyColors & s3rd
iMinRemain = iMinRemain Mod 48

Call Get4thColor(iMinRemain, sMyColors, sRemain)

End Sub
'**************************************************************
Sub Get4thColor(iMinRemain As Integer, sMyColors As String, sRemain As String)

Dim s4th As String

Select Case iMinRemain
Case Is < 12
s4th = Mid(sRemain, 1, 1)
sRemain = Mid(sRemain, 2, 3)
Case 12 To 23
s4th = Mid(sRemain, 2, 1)
sRemain = Mid(sRemain, 3, 2) & Mid(sRemain, 1, 1)
Case 24 To 35
s4th = Mid(sRemain, 3, 1)
sRemain = Mid(sRemain, 4, 1) & Mid(sRemain, 1, 2)
Case 36 To 47
s4th = Mid(sRemain, 4, 1)
sRemain = Mid(sRemain, 1, 3)
End Select

sMyColors = sMyColors & s4th
iMinRemain = iMinRemain Mod 12

Call Get5thColor(iMinRemain, sMyColors, sRemain)

End Sub
'**************************************************************
Sub Get5thColor(iMinRemain As Integer, sMyColors As String, sRemain As String)

Dim s5th As String

Select Case iMinRemain
Case Is < 4
s5th = Mid(sRemain, 1, 1)
sRemain = Mid(sRemain, 2, 2)
Case 4 To 7
s5th = Mid(sRemain, 2, 1)
sRemain = Mid(sRemain, 3, 1) & Mid(sRemain, 1, 1)
Case 8 To 11
s5th = Mid(sRemain, 3, 1)
sRemain = Mid(sRemain, 1, 2)
End Select

sMyColors = sMyColors & s5th
iMinRemain = iMinRemain Mod 4

Call Get6and7thColors(iMinRemain, sMyColors, sRemain)

End Sub
'**************************************************************
Sub Get6and7thColors(iMinRemain As Integer, sMyColors As String, sRemain As String)

Dim s6th As String

Select Case iMinRemain
Case Is < 2
s6th = Mid(sRemain, 1, 1)
sRemain = Mid(sRemain, 2, 1)
Case 2 To 3
s6th = Mid(sRemain, 2, 1)
sRemain = Mid(sRemain, 1, 1)
End Select

sMyColors = sMyColors & s6th & sRemain

txtSequence.visible = "true"
txtSequence.text = sMyColors

Call ShowColors(sMyColors)

End Sub
'**************************************************************
Sub ShowColors(sMyColors as string)

Dim sColor(6) as string
Dim i as integer
Dim Color as string
Dim txtColors as textBox
'Dim sLetter as string

sColor(0) = Left(sMyColors,1)
sColor(1) = Mid(sMyColors,2,1)
sColor(2) = Mid(sMyColors,3,1)
sColor(3) = Mid(sMyColors,4,1)
sColor(4) = Mid(sMyColors,5,1)
sColor(5) = Mid(sMyColors,6,1)
sColor(6) = Mid(sMyColors,7,1)

For i = 0 to 6
Select case sColor(i)
Case "G"
Color = "purple"
Case "F"
Color = "blueviolet"
Case "E"
Color = "blue"
Case "D"
Color = "green"
Case "C"
Color = "yellow"
Case "B"
Color = "orange"
Case "A"
Color = "red"
End Select

txtColors = CType(FindControl("txt" & i+1), TextBox)
txtColors.backcolor = ColorTranslator.FromHtml(Color)

Next i

btnJavaScript.text = "Display Colors"
Call RunJavaScript( )

End Sub
'**************************************************************
Sub RunJavaScript()

btnJavaScript.Attributes.Add("onClick", "return enterColorString( );")

End Sub
'**************************************************************
</script>

<html>
<head>

<script language = "JavaScript">

var theTimeout;
var colorString;
var strColor;
var sFont;
var intNum = 0;
var intSecs;
var intTotalSecs;
var index;

function enterColorString( )
{
colorString = document.getElementById("txtSequence").value ;

//intSecs = prompt("How many seconds between color changes?", "5");
intSecs = 5
intTotalSecs = parseInt(intSecs) * 1000
upDate( );
}

function upDate()
{
var theNumber = intNum;
var theNumberLoop = (theNumber % 7) + 1;

theNumber = parseInt(theNumber) + 1;
intNum = theNumber;
theTimeout = setTimeout("upDate();", intTotalSecs)

getColors();

switch (theNumberLoop)
{
case 1:
document.bgColor = strColor[0];
lbl1.innerText="I'm having the time of my life!";
break;
case 2:
document.bgColor = strColor[1];
lbl1.innerText="No worries on my mind!";
break;
case 3:
document.bgColor = strColor[2];
lbl1.innerText="Everything is just fine!";
break;
case 4:
document.bgColor = strColor[3];
lbl1.innerText="Today is even better than yesterday!";
break;
case 5:
document.bgColor = strColor[4];
lbl1.innerText="Everything is going my way!";
break;
case 6:
document.bgColor = strColor[5];
lbl1.innerText="I'm living in the big time!";
break;
case 7:
document.bgColor = strColor[6];
lbl1.innerText="Generating my daily income is surprisingly fun & easy!";
break;
}
}

function getColors( )
{
strColor = new Array(colorString.substring(0,1), colorString.substring(1,2), colorString.substring(2,3), colorString.substring(3,4),
colorString.substring(4,5), colorString.substring(5,6), colorString.substring(6,7))

for (index = 0; index <7; index++)
{
switch (strColor[index])
{
case "G":
strColor[index] = "purple";
break;
case "F":
strColor[index] = "blueviolet";
break;
case "E":
strColor[index] = "blue";
break;
case "D":
strColor[index] = "green";
break;
case "C":
strColor[index] = "yellow";
break;
case "B":
strColor[index] = "orange";
break;
case "A":
strColor[index] = "red";
break;
}
}
}
</script>

<style type="text/css">
.mytable
{ font-family:sans-serif;
font-size:8pt;
color:black; }
</style>
</head>
<body>

<form runat='server'>
<table class = 'myTable'>
<tr>
<td width='50'><ASP:label ID='lblmonths' text='Month' font-bold='true' runat='server' /></td>
<td width='50'><ASP:label ID='lbldays' text='Day' font-bold='true' runat='server' /></td>
<td width='50'><ASP:label ID='lblyears' text='Year' font-bold='true' runat='server' /></td>

<td width='50'><ASP:label ID='lblHour' text='Hour' font-bold='true' runat='server' /></td>
<td width='50'><ASP:label ID='lblMin' text='Min' font-bold='true' runat='server' /></td>
<td width='50'><ASP:label ID='lblAMPM' text='AM/PM' font-bold='true' runat='server' /></td>
</tr>
<tr>
<td><ASP:DropDownList ID='ddlmonths' runat='server' /></td>
<td><ASP:DropDownList ID='ddldays' runat='server' /></td>
<td><ASP:DropDownList ID='ddlyears' runat='server' /></td>

<td><ASP:DropDownList ID='ddlHour' runat='server' /></td>
<td><ASP:DropDownList ID='ddlMin' runat='server' /></td>
<td><ASP:DropDownList ID='ddlAMPM' runat='server' /></td>

<td>
<asp:TextBox Id='txt1' width='20' height='20' runat='server' />
</td>
<td>
<asp:TextBox Id='txt2' width='20' height='20' runat='server' />
</td>
<td>
<asp:TextBox Id='txt3' width='20' height='20' runat='server' />
</td>
<td>
<asp:TextBox Id='txt4' width='20' height='20' runat='server' />
</td>
<td>
<asp:TextBox Id='txt5' width='20' height='20' runat='server' />
</td>
<td>
<asp:TextBox Id='txt6' width='20' height='20' runat='server' />
</td>
<td>
<asp:TextBox Id='txt7' width='20' height='20' runat='server' />
</td>
<td>
<asp:TextBox id='txtSequence' visible = 'false' font-size='12pt' font-bold='true' width = '90' runat='Server'/>
</td>
<td>
<ASP:button width='100' Id='btnJavaScript' on_click='Get1stColor' Text='Get Sequence' font-bold='true' runat='server' />
</td>
</tr>
</table><br>

<asp:label ID = 'lblAffirm' runat='Server'/>

</form>
</body>

<body language=JavaScript onload="return window_onload( )">
<form name = "theForm">
<input type = 'button' value = 'Stop' onClick = 'clearTimeout(theTimeout);'><br><br><br><br>
<table align = 'center' valign='middle'>
<tr>
<td><font color = "white" size='7'><label ID="lbl1"></label></font></td>
</tr>
</table>
</form>
</body>
</html>
 
It sounds like a JavaScript issue now so I think you'll be best off posting the resulting HTML (from the View Source menu) in the JavaScript forum.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top