Link to home
Start Free TrialLog in
Avatar of G_M
G_MFlag for Australia

asked on

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
ASKER CERTIFIED SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of G_M

ASKER

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  :-)
Sure.  Have a good time.

Rob.
Avatar of G_M

ASKER

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
No problem. Thanks for the grade.  I hope you can understand how I implemented it.

Rob.