I need to make something that will automatically insert values into a letter based on user input, just like this one right here. please tell me how it works....
It is no more than a series of select lists from which the user may choose an option.
Code:
<select id = "list1">
<option value = "">Choose a recipient</option>
<option value = "Father">Father</option>
<option value = "Mother">Mother</option>
<option value = "Grandma">Grandma</option>
</select>
<input type = "button" value = "Generate Letter" onclick = "generate()">
<br><br>
<div id = "letter">
</div>
<script type = "text/javascript">
function generate() {
var r = document.getElementById("list1").value;
if (r!="") {
var message = "Dear " + r + ",";
document.getElementById("letter").innerHTML = message;
}
}
</script>
All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.
It is no more than a series of select lists from which the user may choose an option.
Code:
<select id = "list1">
<option value = "">Choose a recipient</option>
<option value = "Father">Father</option>
<option value = "Mother">Mother</option>
<option value = "Grandma">Grandma</option>
</select>
<input type = "button" value = "Generate Letter" onclick = "generate()">
<br><br>
<div id = "letter">
</div>
<script type = "text/javascript">
function generate() {
var r = document.getElementById("list1").value;
if (r!="") {
var message = "Dear " + r + ",";
document.getElementById("letter").innerHTML = message;
}
}
</script>
All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.
thanks dude, i havent tried it yet but i'll let you know.
No - var r = document.getElementById("list1").value; is just fine.
are you sure about that always and everywhere?
EDIT
i know there's got to be a reason i've been doing that stupid x.options [x.selectedIndex ] crap for years...
i'm almost certain that it won't work in IE6, but seeing as IE6 sucks and i don't have a copy of IE6, I'll concede the point.
makes me wonder how long setting the .value of a select has worked as well...
If that's the only reason, screw IE6, i'm going for the .value from now on.
__________________ my site (updated 5/13) STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.8% IE9:11.4% IE10:6.5%
EDIT
i know there's got to be a reason i've been doing that stupid x.options [x.selectedIndex ] crap for years...
i'm almost certain that it won't work in IE6, but seeing as IE6 sucks and i don't have a copy of IE6, I'll concede the point.
makes me wonder how long setting the .value of a select has worked as well...
If that's the only reason, screw IE6, i'm going for the .value from now on.
No, I am not sure as there are there are a bunch of marginal browsers out there such as Konqueror and Lunescape. But it works in IE (including IE6 ), FF and (I am pretty sure) Opera.