[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 7424
  • Last Modified:

VBScript in HTML - Change label value on button click

Hey guys,

I have a HTA that I am building for an sms and email function we are looking to utilise on our network. I am new to HTAs and am trying to funnel in the current VBScript we have to do this function to make the process more user friendly.

I am stuck trying to update a label value in the HTA that will display a valid phone number and store it in the strPhone & intNum variable to be used later.

Can someone help me fix this code so it updates the "lblN1" label (line 70) with the strPhone contents.

<html>
<head>
    <META http-equiv="Content-Style-Type" content="text/css">
    <title>Site Code</title>
<style>
body {
font-family:Calibri;
font-size: 12px;
filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr=#BAD7F0, EndColorStr=#7BB2E3);
color: #49403B;
background: #FFFFFF;
}
 
button {
font-family:Calibri;
font-size: 12px;
filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr=#FFFFFF, EndColorStr=#7BB2E3);
height: 25px;
width: 75px;
font-weight: normal;
}
hr {color: #7BB2E3;}
textarea {background-color: #FFFFD5;}
input {background-color: #FFFFD5;}
</style>
 
<script language="vbscript">

Sub Window_Onload()
	intNum = 1
	Set objForm = Document.forms("MessageSender")
    Center_HTA 393, 550
    objForm.txt_Phone.Focus
End Sub
  
Sub Center_HTA(intWidth, intHeight)
x = (window.screen.width - intWidth) / 2
y = (window.screen.height - intHeight) / 2
If x < 0 Then x = 0
If y < 0 Then y = 0
window.resizeTo intWidth,intHeight
window.moveTo x,y
End Sub


Sub Send_Message(strMsg)
    MsgBox(strMsg)
End Sub


Sub HTA_Close()
    self.close()
End Sub


Sub Add_Phone(strPhone)
	
	Set objDic = CreateObject("Scripting.Dictionary")
	Set objForm = Document.forms("MessageSender")
		
	If Not IsNumeric(strPhone) Then
		MsgBox "Please enter a valid mobile phone number", vbOKOnly+vbCritical, "Error!"
	ElseIf strPhone = "" Then
		MsgBox "Please enter a mobile phone number", vbOKOnly+vbCritical, "Error!"
	ElseIf Mid(strPhone, 1, 2) <> "04" Then 
		MsgBox "Please enter a valid mobile phone number", vbOKOnly+vbCritical, "Error!"
	ElseIf Len(strPhone) <> 10 Then
		MsgBox "Please enter a valid mobile phone number", vbOKOnly+vbCritical, "Error!"
	Else
		lblN1.Caption = objLblEdit.strPhone
		strPhone & intNum = strPhone
		intNum = intNum + 1
	End If
	
End Sub


Sub Add_Email(strEmail)
If strEmail = "" Then
MsgBox("Please enter an email address")
End If
End Sub
</script>


 <hta:application
  applicationname="Site Code"
  border="dialog"
  borderstyle="normal"
  caption="yes"
  contextmenu="no"
  icon="no.ico"
  maximizebutton="no"
  minimizebutton="yes"
  navigable="yes"
  scroll="no"
  selection="yes"
  showintaskbar="yes"
  singleinstance="yes"
  sysmenu="yes"
  version="1.0"
  windowstate="normal">


</head>
    <body>
		<form id="MessageSender">
			<center>
				<div id="Header"><h2>Send Message</h2></div>
				<div id="Inputs" style="height:240px;width:100px;float:left;text-align:left;">
				<br><br>
				<text>Add phone no:</text>
				<input type="text" size="10" name="txt_Phone"/>
				<br><br>
				<button class="button" id="btn_Phone" style="width:87px" onClick="Add_Phone(txt_Phone.Value)" 
				title="Add a phone number to list...">Add Number</button>
				<br><br>
				<text>Add username:</text>
				<input type="text" size="10" name="txt_Email"/>
				<br><br>
				<button class="button" id="btn_Phone" style="width:87px" onClick="Add_Email(txt_Email.Value)" 
				title="Add an email address to list...">Add Email</button></div> 
				<div id="Content" style="height:240px;width:240px;float:left;">
				<textarea name="Message" rows="15" cols="29">Type your message here...</textarea><br><br/></div>
				<div id="Buttons" style="height:40px;width:340px;text-align:center;">
				<button class="button" id="btn_Undo" onClick="Send_Message(txt_Phone.Value)" 
				title="Undo last input...">Undo</button>&nbsp&nbsp&nbsp
				<button class="button" id="btn_Reload" onClick="Send_Message(txt_Phone.Value)" 
				title="Reload Page...">Reload</button>&nbsp&nbsp&nbsp
				<button class="button" id="btn_Send" onClick="Send_Message(txt_Email.Value)" 
				title="Send Message...">Send</button>&nbsp&nbsp&nbsp
				<button class="button" id="btn_Exit" onClick="HTA_Close()" 
				title="Exit this application...">Exit</button>
				</div>
				<div id="OutputPhone" style="height:100px;width:170px;float:left;text-align:center;"><h5>Phone Numbers:</h5>
				<label name="lblN1" id="N1"></label>
				<label for="Number2"></label>
				<label for="Number3"></label>
				<label for="Number4"></label>
				<label for="Number5"></label>
				</div>
				<div id="OutputEmail" style="height:100px;width:170px;float:right;text-align:center;"><h5>Email Addresses:</h5>
				<label for="Email1"></label>
				<label for="Email2"></label>
				<label for="Email3"></label>
				<label for="Email4"></label>
				<label for="Email5"></label>
				</div>
			</center>
		</form>
	</body>
</html>

Open in new window


Hope someone can help.
Cheers
G_M
0
G_M
Asked:
G_M
  • 3
  • 2
1 Solution
 
RobSampsonCommented:
Hi G_M,

I have changed your labels to SPAN elements, and made the button populate up to 5 numbers.

I took out your number increment to, since I'm not sure what that was for.

Let me know if you have any more questions.

Regards,

Rob.

<html>
<head>
    <META http-equiv="Content-Style-Type" content="text/css">
    <title>Site Code</title>
<style>
body {
font-family:Calibri;
font-size: 12px;
filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr=#BAD7F0, EndColorStr=#7BB2E3);
color: #49403B;
background: #FFFFFF;
}
 
button {
font-family:Calibri;
font-size: 12px;
filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr=#FFFFFF, EndColorStr=#7BB2E3);
height: 25px;
width: 75px;
font-weight: normal;
}
hr {color: #7BB2E3;}
textarea {background-color: #FFFFD5;}
input {background-color: #FFFFD5;}
</style>
 
<script language="vbscript">

Sub Window_Onload()
	Set objForm = Document.forms("MessageSender")
    Center_HTA 393, 550
    objForm.txt_Phone.Focus
End Sub
  
Sub Center_HTA(intWidth, intHeight)
x = (window.screen.width - intWidth) / 2
y = (window.screen.height - intHeight) / 2
If x < 0 Then x = 0
If y < 0 Then y = 0
window.resizeTo intWidth,intHeight
window.moveTo x,y
End Sub


Sub Send_Message(strMsg)
    MsgBox(strMsg)
End Sub


Sub HTA_Close()
    self.close()
End Sub


Sub Add_Phone(strPhone)
	
	Set objDic = CreateObject("Scripting.Dictionary")
	Set objForm = Document.forms("MessageSender")
		
	If Not IsNumeric(strPhone) Then
		MsgBox "Please enter a valid mobile phone number", vbOKOnly+vbCritical, "Error!"
	ElseIf strPhone = "" Then
		MsgBox "Please enter a mobile phone number", vbOKOnly+vbCritical, "Error!"
	ElseIf Mid(strPhone, 1, 2) <> "04" Then 
		MsgBox "Please enter a valid mobile phone number", vbOKOnly+vbCritical, "Error!"
	ElseIf Len(strPhone) <> 10 Then
		MsgBox "Please enter a valid mobile phone number", vbOKOnly+vbCritical, "Error!"
	Else
		If Number1.InnerHTML = "" Then
			Number1.InnerHTML = MessageSender.txt_Phone.Value
		ElseIf Number2.InnerHTML = "" Then
			Number2.InnerHTML = MessageSender.txt_Phone.Value
		ElseIf Number3.InnerHTML = "" Then
			Number3.InnerHTML = MessageSender.txt_Phone.Value
		ElseIf Number4.InnerHTML = "" Then
			Number4.InnerHTML = MessageSender.txt_Phone.Value
		ElseIf Number5.InnerHTML = "" Then
			Number5.InnerHTML = MessageSender.txt_Phone.Value
		Else
			MsgBox "You have added the maximum amount of numbers."
		End If
	End If
	
End Sub


Sub Add_Email(strEmail)
If strEmail = "" Then
MsgBox("Please enter an email address")
End If
End Sub
</script>


 <hta:application
  applicationname="Site Code"
  border="dialog"
  borderstyle="normal"
  caption="yes"
  contextmenu="no"
  icon="no.ico"
  maximizebutton="no"
  minimizebutton="yes"
  navigable="yes"
  scroll="no"
  selection="yes"
  showintaskbar="yes"
  singleinstance="yes"
  sysmenu="yes"
  version="1.0"
  windowstate="normal">


</head>
    <body>
		<form id="MessageSender">
			<center>
				<div id="Header"><h2>Send Message</h2></div>
				<div id="Inputs" style="height:240px;width:100px;float:left;text-align:left;">
				<br><br>
				<text>Add phone no:</text>
				<input type="text" size="10" id="txt_Phone" name="txt_Phone"/>
				<br><br>
				<button class="button" id="btn_Phone" style="width:87px" onClick="Add_Phone(txt_Phone.Value)" 
				title="Add a phone number to list...">Add Number</button>
				<br><br>
				<text>Add username:</text>
				<input type="text" size="10" name="txt_Email"/>
				<br><br>
				<button class="button" id="btn_Phone" style="width:87px" onClick="Add_Email(txt_Email.Value)" 
				title="Add an email address to list...">Add Email</button></div> 
				<div id="Content" style="height:240px;width:240px;float:left;">
				<textarea name="Message" rows="15" cols="29">Type your message here...</textarea><br><br/></div>
				<div id="Buttons" style="height:40px;width:340px;text-align:center;">
				<button class="button" id="btn_Undo" onClick="Send_Message(txt_Phone.Value)" 
				title="Undo last input...">Undo</button>&nbsp&nbsp&nbsp
				<button class="button" id="btn_Reload" onClick="Send_Message(txt_Phone.Value)" 
				title="Reload Page...">Reload</button>&nbsp&nbsp&nbsp
				<button class="button" id="btn_Send" onClick="Send_Message(txt_Email.Value)" 
				title="Send Message...">Send</button>&nbsp&nbsp&nbsp
				<button class="button" id="btn_Exit" onClick="HTA_Close()" 
				title="Exit this application...">Exit</button>
				</div>
				<div id="OutputPhone" style="height:100px;width:170px;float:left;text-align:center;"><h5>Phone Numbers:</h5>
				<span id="Number1"></span><br>
				<span id="Number2"></span><br>
				<span id="Number3"></span><br>
				<span id="Number4"></span><br>
				<span id="Number5"></span>
				</div>
				<div id="OutputEmail" style="height:100px;width:170px;float:right;text-align:center;"><h5>Email Addresses:</h5>
				<span id="Email1"></span>
				<span id="Email2"></span>
				<span id="Email3"></span>
				<span id="Email4"></span>
				<span id="Email5"></span>
				</div>
			</center>
		</form>
	</body>
</html>

Open in new window

0
 
G_MAuthor Commented:
Hey Rob, thank you for the response. I am going on holiday for 10 days and an unable to test your code until I'm back.  I will post the results then.

Thanks again  :-)
0
 
RobSampsonCommented:
Sure.  Have a good time.

Rob.
0
 
G_MAuthor Commented:
Thanks very much Rob, This solution worked a treat exectly as is.

I have modified my code too much since testing to post anything useful and relevant, but the code you provided works without modification.

Cheers
G_M
0
 
RobSampsonCommented:
No problem. Thanks for the grade.  I hope you can understand how I implemented it.

Rob.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now