Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...This site is a great forum to exchange knowledge..."

Geography

Where in the world do Tek-Tips members come from?

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

DougP (MIS)
27 May 12 23:58
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

feherke (Programmer)
28 May 12 3:29
Hi

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

Feherke.
http://feherke.github.com/

BillyRayPreachersSon (Programmer)
28 May 12 19:06

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

@ Code Couch: http://www.codecouch.com/dan/

@ Twitter: http://twitter.com/SleepyDrunkDan

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close