Best Practice If Then Else
May 21, 2006
I'm wondering what the best practice is for a particular task I'm trying to
accomplish. I'm using two sets of radio buttons for a user to select values
from. These values then go into a couple of tables to show some heat loss
calculations depending on the values chosen I want the tables to have the
relevant values filled in. Is the best way to accomplish this a long list of
if then else type statements or is there a better way of doing this?
View 9 Replies
Jul 20, 2005
I am looking for advice on what is "best practice" regarding looping
through a form to check its checkboxes and associated data fields.
Here is what I am trying to do (Here is the page I am working on:
http://www3.telus.net/thothworks/LinLeastSqPoly4.html).
I provide a form for a user to enter up to twenty (M = 20) data pairs.
The user need not enter data for all twenty pairs, but
the user must indicate that data is present by checking the checkbox
beside each valid pair.
If a checkbox is checked, two things happen:
i) a counter, numRows, is incremented to keep track of the total
number of valid pairs entered.
ii) the associated two data values (being x and y) are checked to
ensure that they are valid numbers and, if so, are entered in an array
for use later.
Previously, my forms were small, and I was able to examine each
checkbox of a form individually:
"if (checkbox1.checked) do action A;
if (checkbox2.checked) do action B;
if (checkbox3.checked) do action C;
etc."
However, now that my form has twenty checkboxes, and may get bigger, I
would like to learn how to accomplish this task with a concise loop.
Following is my first attempt and it seems to work. If anyone can
suggest improvements for this code ....
View 4 Replies
View Related
Oct 16, 2007
I have been going back and getting rid of so many of my onclick's and such, trying to switch to a more unobtrusive method of adding events to anchors.
I've run into one snag that's kind of dissonant for me, and wondered if anyone had any advice.
By adding an event, you can turn:
<a href="#" onclick="something(); return false;>Click me</a>
Into:
<a href="new.html" class="something">Click Me</a>
But what goes in href if you don't have anything to actually link to? One example is a page I've written that is entirely self-contained, and all href's that drive the interface end up pointing to #. Is this acceptible in edge cases like these with the unobtrusive approach?
If someone has JS turned off the markup is essentially meaningless, so I was wondering how people deal with this lapse in the separation between behavior and structure.
View 2 Replies
View Related
Apr 14, 2010
I have a photo blog [url] and want to create an effect that fades-in the displayed picture when the page is loaded.
An important requirement for me would be that the page also has to work without Javascript.
Currently I am using the following small plugin:
It is called directly beneath the <img> element:
This way it works fine with the current versions of Firefox and IE. I did not test other browsers or versions yet. I tried to call it in $(document).ready but then IE might display the picture shortly before it is hidden and faded-in.
Since I am not 100% happy with having the code in the middle of the HTML and with depending on the timing of execution to avoid flickering I wanted to ask for other solution or best practices to achieve what I would like to do.
One solution that came to my mind is to do create the image in JScript and only fade it in after it is loaded. To work without Javascript I could still put the <img> element where it was but within a <noscript> element. But not sure how well the <noscript> is supported by older or exotic browsers.
View 2 Replies
View Related
Jul 13, 2010
Which is considered best practice?
<div onmouseover="doThis();">
myDiv.onmouseover = doThis;
myDiv.addEventListener("mouseover",doThis,false);
...or something else?
View 3 Replies
View Related
Jun 29, 2007
I just wanted to get your opinions on this: I have several pages with page-specific JavaScript (i.e. script I know cannot be reused...it can only be run against elements found only on that page).
My question is, would you recommend just putting it in SCRIPT tags in the header, or should I create thispage.js so that the code is separated into another file? It slows the request because the browser has to ask for another external file, but keeps code out of the HTML doc.
View 5 Replies
View Related
May 10, 2011
Consider the following simplified example javascript code...
What's the "best" way to write that onclick method in its current context? I can think of a few ways to do it -- but they all seem fairly "dirty."
Have I gone stupid?
View 8 Replies
View Related
Jun 18, 2011
I want to create a website where you can practice mathematical skills through gaming, but I don't know which web program will be the best for that type of game. I want to learn javascript because I know it is the most widely used language, but I also want to use c# because I have more knowledge in c++ so I'm guessing it will be easier for me to use. And then there's flashplayer, which I've heard is even more easier to use out of all of them. So I ask which console is the best choice?
View 1 Replies
View Related