...

View Full Version : 3 Radio Buttons to Auto Populate a Text Box



Neil Lindsey
09-22-2006, 04:59 PM
Can you please help me?

I have a simple form in html with 3 radio Buttons and a text box.

I simply want to get the text box to display the value of the radio button clicked

This must be a stroll in the park for you guys out there but for a novice like me it seems impossible.

Many thanks for your help

kind regards

Neil

BonRouge
09-22-2006, 05:43 PM
You can do it like this:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Value of radio buttons appearing in text box</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style type="text/css">
* {
margin:0;
padding:0;
}
body {
background-color:white;
}
label {
display:block;
margin:10px;
}
</style>
<script type="text/javascript">
function fillBox() {
var tradio=document.theform.hobby;
for (j=0; j<tradio.length; j++) {
tradio[j].onclick=function() {
for (i=0; i<tradio.length; i++) {
if (tradio[i].checked==true) {
document.theform.hobbyinput.value=tradio[i].value;
}
}
}
}
}
window.onload=fillBox;
</script>
</head>
<body>
<form name="theform" id="theform">
<fieldset>
<legend>Legend</legend>
<label>Which of these do you most enjoy? <input type="text" name="hobbyinput" /></label>
<label>Crocodile hunting <input type="radio" name="hobby" value="Crocodile hunting" /></label>
<label>Playing with wild dogs <input type="radio" name="hobby" value="Playing with wild dogs" /></label>
<label>Reading Schopenhauer <input type="radio" name="hobby" value="Reading Schopenhauer" /></label>
</fieldset>
</form>
</body>
</html>

Neil Lindsey
09-22-2006, 06:59 PM
Dear bonrouge

Thank you so much for your help

You are a star, it works beautifully


Kind regards

Neil



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum