Sarah West said:
>
>Hi,
>
>I have the following problem;
>
>This is my form, i would like to default the select box to USA, and default
>the text field to a name such as 'Sarah' and the hidden field to another
>number like '876543', when the user clicks on the check box, otherwise the
>fields should be blank, the value of the select box dosnt matter much, only
>that it defaults to USA, when the user checks it. Can anyone help? i have
>tried a google with no luck, anything would be appreciated.
>--
> <form name="form1">
> <input type="checkbox" name="checkbox" value="checkbox">
>
> <select name="prefix">
> <option value="off" selected>Select country
> <option value="61">Australia
> <option value="1">USA
> <option value="58">Venezuela
> </select>
>
> <input type="text" name="name">
> <input type="hidden" name="number">
> </form>
>--
<html>
<head>
<script type="text/javascript">
var defaultValue={ prefix:2, name:"Sarah", number:876543 };
function setDefaults(box){
if(box.checked){
box.form.prefix.selectedIndex=defaultValue.prefix;
box.form.name.value=defaultValue.name;
box.form.number.value=defaultValue.number;
}else{ // clear the values if unchecked
box.form.prefix.selectedIndex=0;
box.form.name.value="";
box.form.number.value="";
}
}
</script>
<body>
<form name="form1">
<input type="checkbox"
name="checkbox"
value="checkbox"
onclick="setDefaults(this)">
<select name="prefix">
<option value="off" selected>Select country</option>
<option value="61">Australia</option>
<option value="1">USA</option>
<option value="58">Venezuela</option>
</select>
<input type="text" name="name">
<input type="hidden" name="number">
</form>
</body>
</html>
|