/    Sign up×
Community /Pin to ProfileBookmark

Set numeric textbox value in javascript

I’m using visual studio 2008 with Rad controls Q3.
My main question is: How do I set the value/text of a numerica text box in javascript code?

I’m using Visual Studio 2008 with Q3. I have a master page with numerous content pages. On one page i have a few numeric textboxes. I have been able to grab the values of the textboxes and do any calculations with them that I need, but I have not been able to write my values into another textbox. How do I do this? Here’s all my code for this so far.
(Masterpage)

[code=html]<%@ Master Language=”VB” CodeFile=”MasterPage.master.vb” Inherits=”MasterPage” %>

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>

<html xmlns=”http://www.w3.org/1999/xhtml”>
<head runat=”server”>
<title>Untitled Page</title>
<asp:ContentPlaceHolder id=”head” runat=”server”>
</asp:ContentPlaceHolder>
</head>
<body bgcolor=”#cccccc”>
<form id=”form1″ runat=”server”>
<div>
<script type=”text/javascript”>
function TestCalc(te, ca, db)
{
alert(“Calculating”);
var totalExpenses = document.getElementById(te).value;
var cashAdvance = document.getElementById(ca).value;
var directBillings = document.getElementById(db).value;
var due = (totalExpenses – cashAdvance – directBillings);
//cashAdvance.SetValue(directBillings);
//cashAdvance.innerHTML = 0;
//ca.innerHTML = 0;
//document.getElementById(ca).innerHTML = “0”;

// if (due < 0)
// {
// var DueAmount = (due * (-1));
// var DueEmployer = document.getElementById(der);
// alert(DueEmployer.value);
// DueEmployer.Value = DueAmount;
// alert(DueEmployer.value);
//
// }
// else{
// var DueAmount = due;
// var DueEmployee = document.getElementById(dee).value;
// dee.SetValue(DueAmount);
// }

}
</script>
<asp:ContentPlaceHolder id=”ContentPlaceHolder1″ runat=”server”>

</asp:ContentPlaceHolder>
</div>
</form>
</body>
</html> [/code]

Default.aspx

[CODE]Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
RadNumericTextBox1.Attributes.Add(“onBlur”, “TestCalc(‘” & RadNumericTextBox1.ClientID & “‘, ‘” & RadNumericTextBox2.ClientID & “‘, ‘” & RadNumericTextBox3.ClientID & “‘)”)
End Sub[/CODE]

[code=html]<%@ Page Language=”VB” MasterPageFile=”~/MasterPage.master” AutoEventWireup=”false” CodeFile=”Default.aspx.vb” Inherits=”_Default” title=”Untitled Page” %>

<%@ Register assembly=”RadInput.Net2″ namespace=”Telerik.WebControls” tagprefix=”rad” %>

<asp:Content ID=”Content1″ ContentPlaceHolderID=”head” Runat=”Server”>
</asp:Content>
<asp:Content ID=”Content2″ ContentPlaceHolderID=”ContentPlaceHolder1″ Runat=”Server”>
<p>
<br />
<table style=”width: 27%;”>
<tr>
<td>
<rad:RadNumericTextBox ID=”RadNumericTextBox1″ Runat=”server”>
</rad:RadNumericTextBox>
</td>
<td>
&nbsp;</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
<rad:RadNumericTextBox ID=”RadNumericTextBox2″ Runat=”server”>
</rad:RadNumericTextBox>
</td>
<td>
&nbsp;</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
<rad:RadNumericTextBox ID=”RadNumericTextBox3″ Runat=”server”>
</rad:RadNumericTextBox>
</td>
<td>
&nbsp;</td>
<td>
&nbsp;</td>
</tr>
</table>
</p>
</asp:Content> [/code]

Any help would be greatly appreciated. Please let me know if more information is needed. Thanks!

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@magentaplacentaJan 14.2008 — I don't know asp, but this copies whatever you enter in the first textbox into the second.

[CODE]<script type="text/javascript">
function copyValue() {
var textbox1 = document.getElementById("textbox1");
var textbox2 = document.getElementById("textbox2");

textbox2.value = textbox1.value;
}
</script>


<form>
<input type="textbox" id="textbox1">
<input type="button" value="Copy value -->" onclick="copyValue();">
<input type="textbox" id="textbox2">
</form>[/CODE]
Copy linkTweet thisAlerts:
@manaredJan 15.2008 — I never did try the '.value' onto the end of the variable I was assigning to the textbox, so I tried it out and it still doesn't work. I don't get any errors, but the textbox doesn't show the new value that I assign it.
×

Success!

Help @Big_Red spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.8,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...