tinyMan":3m3ozijj said:
Trivial projects are even more trivial-er if you start with a a good baseline for all your projects. Having to make a decision at the beginning of a project to use your standard or not adds complication. Use the standard boilerplate code everywhere, use the tests every time and do the standard best-practices js and css compression for every project.
Doing things the same way every time is easier and has a higher quality end result than inventing a "shorter" path for projects that seem "easy."
If one thing has held true over my life, its that easy/quick/one-off projects are the ones that end up in production and being supported for years and years. Make life easy on your future self.
I agree with that sentiment, but looking through HTML 5 Boilerplate seems like a waste of time. I'm not building a big beautiful webpage, I'm just trying to automate name generation. Also, I see being more verbose as a plus, not a negative- if I ever have to explain this to another fellow non-web designer, I'm not going to remember what "$('#shortword :selected").text() + ' - ' + $('#longword :selected').text();" means, but reading "document.forms[0].shortword1.options[document.forms[0].shortword1.selectedIndex].getAttribute('shortvalue')", although much longer, is pretty straightforward.
As a minor illustration, I just had a sales guy come by and ask what the flow coefficient of a valve means. I could have gone into specific gravity and so on, but instead told him "It's a value that lets you compare flow rates between valves, regardless of the fluid or pressure. Higher Cv values generally correspond to a higher flow rate for a given fluid and pressure." Yesterday, a guy in the shop asked how high to torque some bolts. I didn't hand him a copy of ASME B1.1 and API 6A and suggest he go nuts, I just opened the spreadsheet I wrote for myself, estimated the coefficient of friction, and rounded it off to a nice round number that his torque wrench supports ("Torque them to 40 ft-lbs").
My point isn't that any professional should condone ugly hacks and shortcuts, but just that sometimes you don't need to know every detail. I don't mean any disrespect by that- I have seen many of the programs and webpages that Arsians have made over the years, and been very impressed.
technophile":3m3ozijj said:
Hm. You'll basically need to get the currently selected <option> and then call its getAttribute method, if I'm understanding the question correctly.
Something like:
Code:
document.forms[0].shortword1.options[document.forms[0].shortword1.selectedIndex].getAttribute('shortvalue')
should get what you want, given the above markup, IIRC.
The other way to go would be to just set the value of each option as the short value, and use the text of each option as the long value; this is probably what I would do.
I'm trying both of these today, but the second one does sound easier. I tried
Code:
<script type="text/javascript">
function combName()
{
var word1 = document.forms[0].word1.value;
var word2 = document.forms[0].word2.value;
document.forms[0].name.value = word1+word2;
var shortword1 = document.forms[0].shortword1.value
var shortword2 = document.forms[0].shortword2.value
document.forms[0].shortname.value = shortword1+shortword2;
}
</script>
<form action="#" method="post">
<select name="word1" onchange="document.forms.word1.value=this.text; document.forms.shortword1.shortvalue=this.value" onclick="combName()">
<option value="Word1 Option1" shortvalue="W1O1">Word1 Option1</option>
<option value="Word1 Option2" shortvalue="W1O2">>Word1 Option2</option>
</select>
<select name="word2" onchange="document.forms.word2.value=this.text; document.forms.shortword2.value=this.value" onclick="combName()">
<option value="Word2 Option1" shortvalue="W2O1">Word2 Option1</option>
<option value="Word2 Option2" shortvalue="W2O1">Word2 Option2</option>
</select>
<input type="text" id="name" name="name" size="128" readonly="readonly">
<input type="text" id="shortname" name="shortname" size="40" readonly="readonly">
</form>
but that was gibberish. I'm looking around the web to get a better handle on getAttribute and will try that too.