0

Hello,

I'm wondering how to add predefined text to many input fields on click of an image.

so I have 4 images and I click one and 4 fields are filled with predefined text. If I click another the text is changed with some other predefined text.

Thanks

2
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by reco21
1

I think this may help.

<html>
<head>
<script type="application/javascript">
	function msg() {
		for(var x=1;x<=4;x++) {
			document.getElementById('a' + x).value="hello";
		}
	}
</script>
</head>
<body>
	<img src="" height="50" width="200" onClick="javascript:msg();"><br />
	<input type="text" name="a1" id="a1">
    <input type="text" name="a2" id="a2">
    <input type="text" name="a3" id="a3">
    <input type="text" name="a4" id="a4">
</body>

SNIP

Edited by happygeek: fake sig snipped

0

Thanks. How do I add different text to the fields? Say if it's a name, address, postal code,school.

Edited by reco21: n/a

1

try this.

<html>
<head>
<script type="application/javascript">
	function msg() {
		document.getElementById('a1').value="name";
		document.getElementById('a2').value="address";
		document.getElementById('a3').value="postal";
		document.getElementById('a4').value="school";
	}
</script>
</head>
<body>
	<img src="" height="50" width="200" onClick="javascript:msg();"><br />
	<input type="text" name="a1" id="a1">
    <input type="text" name="a2" id="a2">
    <input type="text" name="a3" id="a3">
    <input type="text" name="a4" id="a4">
</body>

SNIP

Edited by happygeek: fake sig snipped

Votes + Comments
Thanks, again
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.