Jump to content


Photo

Inserting any value into a text box by clicking a button - how?


  • Please log in to reply
5 replies to this topic

#1 Revos

Revos
  • Members
  • PipPip
  • Member
  • 22 posts

Posted 31 August 2006 - 12:48 AM

Hello.
I got button called XX how can I make that when I press the button, the value of text box named XY will change to "444"?


#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 31 August 2006 - 01:07 AM

Use the onClick event to fire off a function like...

function changer() {
  document.form.XY.value = "444";
}


#3 Revos

Revos
  • Members
  • PipPip
  • Member
  • 22 posts

Posted 31 August 2006 - 01:22 AM

I tried this code:
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Document</title>
</head>
<input name="Txt" type="text" value="123" />
<input name="Button1" type="button" value="Bla" onClick= "Document.form.Txt.value = "444" />
<body>
</body>
</html>
but it doesn't work..

#4 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 31 August 2006 - 01:37 AM

You dont have any form in your document and your synatx is slightly off....

<input name="Button1" type="button" value="Bla" onClick='Document.form.Txt.value = "444";' />


#5 syed

syed
  • Members
  • PipPipPip
  • Advanced Member
  • 151 posts
  • LocationEngland

Posted 31 August 2006 - 06:10 AM

As thorpe said you need to create a form tag such as <form name="form1"> all your form objects must go between the form opening and closing tags.

example

<form name="form1">
<input type="text" name="text1" size="20">
<input type="button" value="click me" onClick="document.form1.text1.value='test message'">
</form>

#6 radalin

radalin
  • Members
  • PipPipPip
  • Advanced Member
  • 179 posts

Posted 01 September 2006 - 02:12 PM

if you define the js code in onclick part and not point it to a js function just like this:
<input type="button" value="click me" onClick="text1.value='test message'">

and it will work fine.
Roy Simkes
Yet Another Parkyeri Developer




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users