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 Andrzejek on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie: need help with set a textbox value to combo box value

Status
Not open for further replies.

DougP

MIS
Dec 13, 1999
5,985
US
I have this code which is called by a combo box, on change event. The text box is called txtCatalogID. I figured out how to get the value but cannot set it in the txtCatalogID.
Code:
		function GetNextCategoryNum(sel)
		{
	       		var NextNumber; 
        		var textbox = document.getElementById("txtCatalogID");
       		    var number = parseInt(sel.options[sel.selectedIndex].value); 
        		NextNumber = number + 1;
        		alert("Last number used "  + NextNumber );
                        textbox.value =NextNumber  // this does not work 
        		document.getElementById("txtCatalogID") =NextNumber  // nor this does not work       		
                         document.getElementById("txtCatalogID").value = NextNumber   // nor this does not work       		
			}
the form name is
<form Name="myForm" ....>
CatalogID <input type="text" name="txtCatalogID" size="12"><br>

TIA



DougP
 
Hi

You are trying to get a reference to the element with [tt]id[/tt] txtCatalogID, but probably there is no such element. At least in the HTML fragment you posted there is only an element with [tt]name[/tt] txtCatalogID.

Feherke.
[link feherke.github.com/][/url]
 
As feherke has pointed out, you're trying to use a method that gets an element based on its ID attribute (the clue is in the name), yet your element has no ID attribute.

You could give it an ID, or you could use this syntax to refer to it by its name:

Code:
document.forms['myForm'].elements['txtCatalogID'].value = NextNumber;

Hope this helps,

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[blue]@[/blue] Code Couch:
[blue]@[/blue] Twitter:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top