User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 401,729 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,192 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 2939 | Replies: 3
Reply
Join Date: Jan 2005
Location: defiance, oh
Posts: 19
Reputation: sqlchopper is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 1
sqlchopper sqlchopper is offline Offline
Newbie Poster

Help need help to get document.getElementById to work

  #1  
Apr 11th, 2006
I have created the foloowing javascript and placed it in a file called common.js. it gets called on a onChange event. it works up till it gets to setting the value (i think). Being my first script i'm really at a loss why it errors out. I tried .value() = and .value( prevbal - demand..... TIA

		function recalcnet(txt) {
			switch (txt) {
				case '0' :
				    recalcnet1();
				    break;}}
		function recalcnet1() {
				var prevbal = 0;
				var demand = 0;
				var whatif = 0;
				var sched = 0;
				prevbal = document.getElementById('BegInvTextbox').value;
				demand = document.getElementById('dm1TextBox').value;
				whatif = document.getElementById('ifm1TextBox').value;
				sched = document.getElementById('fmm1TextBox').value;
		        document.getElementById('nm1TextBox').value(prevbal - demand + whatif + sched)};
Last edited by tgreer : Apr 11th, 2006 at 4:07 pm. Reason: Added the ever-missing [code] tags.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2005
Location: Carmel, IN
Posts: 67
Reputation: Sailor_Jerry is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 2
Sailor_Jerry's Avatar
Sailor_Jerry Sailor_Jerry is offline Offline
Junior Poster in Training

Re: need help to get document.getElementById to work

  #2  
Apr 11th, 2006
Here is little example to get you started on debugging. I would place some alerts in there to see what's going on. I am not exactly sure what you’re trying to do with the line below.

You already know the value of prevbal… etc. If you want to set the element below to the value of those numbers try something like I did below. I am guessing those var are numbers. But in your code they will be treated as strings.

document.getElementById('nm1TextBox').value(prevbal - demand + whatif + sched)


<html><head>
<title></title>
<script>
function testFn()
{	
	var test1 = document.getElementById('Num1').value;
	if(test1 != "")
	{
		alert("Number 1: " + test1);
	}
	
	var test2 = document.getElementById('Num2').value;
	if(test2 != "")
	{
		alert("Number 2: " + test2);
	}
	
	if (test1 != "" && test2 != "")
	{
		var test3 = document.getElementById('Total');
		var total = test3.value = parseInt(test1) + parseInt(test2);
		alert("Total Num 1 + Num2: " + total);
	}
}
</script>
</head>

<body>
<label value"num1"> Number 1 </label> <input size="2" id="Num1" onChange="testFn()">
<label value"num2"> + Number 2 </label> <input size="2" id="Num2"  onChange="testFn()">

<label value="fullName"> Total: </label> <input size="4" id="Total" type=text>


</body>
</html> 
Reply With Quote  
Join Date: Jan 2005
Location: defiance, oh
Posts: 19
Reputation: sqlchopper is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 1
sqlchopper sqlchopper is offline Offline
Newbie Poster

Re: need help to get document.getElementById to work

  #3  
Apr 11th, 2006
thanks, the parseInt() worked. why does it treat it as a string.
Reply With Quote  
Join Date: Dec 2004
Posts: 1,590
Reputation: tgreer is an unknown quantity at this point 
Rep Power: 7
Solved Threads: 34
Colleague
tgreer tgreer is offline Offline
Made Her Cry

Re: need help to get document.getElementById to work

  #4  
Apr 11th, 2006
Because JavaScript isn't strongly-typed... and the default type of textboxes and labels is a string.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb JavaScript / DHTML / AJAX Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 9:24 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC