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

Set default value of textbox on onclick from checkbox

Status
Not open for further replies.

jojo79

Programmer
Oct 11, 2006
40
US
I am trying to set the value of a textbox to "transfer" if a checkbox is clicked.

I have tried several ways to accomplish this with no results. Below are 2 ways that I cannot get to work.

Form Name: ipc_pick
Textbox Name: textbox1
Checkbox Name: check

DOES NOT WORK.
Code:
{
  if ( document.all.check.checked )
    ipc_pick.textbox1.value = "transfer"
  	 
  else {}
}

DOES NOT WORK
I just set the onclick event on the checkbox.
Code:
ipc_pick.textbox1.value = "transfer"

 
What browser are you testing in?
This works in IE but not in Firefox.

Document.all is not cross-browser friendly.

Give your input fields an ID tag the same as or in place of the name tag then use the following:
Code:
{
  if ( document.getElementById('check').checked )
    document.getElementById('textbox1').value = "transfer"
  else {
  }
}

This works in IE6 and in Firefox as getElementById is part of the DOM. Then you do not need to even use the form name to access the element.


At my age I still learn something new every day, but I forget two others.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top