Jump to content

Archived

This topic is now archived and is closed to further replies.

Revos

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

Recommended Posts

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"?

Share this post


Link to post
Share on other sites
Use the onClick event to fire off a function like...

[code]
function changer() {
  document.form.XY.value = "444";
}
[/code]

Share this post


Link to post
Share on other sites
I tried this code:
[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>[/code]
but it doesn't work..

Share this post


Link to post
Share on other sites
You dont have any form in your document and your synatx is slightly off....

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

Share this post


Link to post
Share on other sites
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>

Share this post


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

and it will work fine.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.