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 ....
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?
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.
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.
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.
I want to make few forms but 1 submit button. I want to do 1 page , 5 forms , 1 submit button so when i click on the submit button it will send the 5 forms as 1 form.
Where the inputs sum1 and sum2 are text fields you put whatever numbers you want in. That works fine. Great. Now what I'm having trouble with is modifying the code so that it will add one form with an input number with a form that spits out a randomly generated number.
This is what I'm using for my random number generator. So basically I want to be able to put, say, 5, into the input text field above this. And then click on the d20 button to get a random number, say, 15, and then have the first code add the inputted 5 with the randomly generated 15.
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?
Hopefully I 'm missing something silly, but I can't find an easy way to loop all list items in a simple <ol>. I was hoping a for loop as shown below would be enough, however clicking "alert all" in the following example gives me all but the first <li> element. The alertfirst() function finds the first <li> with no problem. There are multiple lists on the page, so getElementsByTagName('li') is probably not the most elegant solution. Btw. my Mozilla crashed when I tried this code, but this is for IE only.
<script type="text/javascript"> function alertfirst() { var ol=document.getElementsByTagName('ol')[0]; alert( ol.firstChild.firstChild.nodeValue ); } function alertall() { var ol=document.getElementsByTagName('ol')[0]; for( var i=ol.firstChild; i=i.nextSibling; i!==null) { alert( i.firstChild.nodeValue ); } } </script> <ol> <li>first</li> <li>second</li> <li>third</li> </ol> <a href="" onclick="alertfirst();return false">alert first</a> <a href="" onclick="alertall();return false">alert all</a>
i am fairly new to javascript and XML. i'm trying to loop through some nodes and drop the output into a series of DIVs using getElementById. here's the code for that: Code:
So, the aim of what I'm doing is to take any amount of text that's in a <textarea>, split it wherever there's a '=====\n' and then call each element of the newly created array back into the <textarea> in a sequential manner.[code]For some reason, my for loop doesn't work. It's only returning the last value in the array and disregarding the previous ones.
I need to loop through all form elements such as text, radios, check boxes and the like and to save their state in a file. does anyone have JS code to do this ?
If got problem with .each looping in jquery. im am trying to make a animation with jQuery. And i want to switch between three quotes of the array. and now it only works for the first quote of the array.
in my code below I am using inlinecontent from thickbox thickbox/) which works but inside the <div id="myOnPageContent"> only shows the first Category Name and doesn't loop through but it is looping outside as it shows a different Category Name at teh top of my inline content
I am practicing looping through a document, finding certain tags and then manipulating them. I have a document with several select tags. 5 of them are very similar showing pirate names. 2 shows pirate ships. The action I would like is if you select a pirate from any select menu, all the other pirate select menus show the same pirate.
This worked as intended until I added the pirate ship select menu to the document. Now for some reason when the script loops through the select tags it is missing some of the pirate ones. The error message I get is that my variable subSelect is null, though it works for some of the loop. I'm not sure why it is dropping it's value.
I have a php page which displays records on the page. I have pagination in these pages which limits the output to a set amount of records per page. As i am designing a display only screen i want it to constantly loop through the links on the page after a set time. My code is:
<script type="text/javascript"> <!-- function delay(){
[code]...
so now it opens screen.php then after 5 secs it goes to screen.php?page=1 (same page) then just keeps refreshing after 5 secs the same page. E.g if i had 10 links on the page i want it to go screen.php?page=2 then page=3 and so on until page=10 then it goes back to the first link i.e page=1 and continuously do this.
I have a list of input1's and inputs2's. The input ones are an accept button and the input2's are a deny button. However, I set up an alert to tell me the name of the input 1's but I am only told the name of the last input1 in my list.
I would like input1.name to show me... something like accept[3]. Where 3 is the uid of the user being accepted or denied. The name works when I look at the source code, but fails when I try to create the alert.
How can I achieve this result?
Code:
So what to do here, thats the question:
- You want to get the data of the button that has been pressed, if such function exists.
- Then use AJAX to send the form data to some file that probably doesnt exist yet.
- Give the PHP a responce, and echot he response to replace the buttons.
I want to use JavaScript so that i can look through the array of these div objects.
var helloDivs = document.getElementByName('hello'); var len = helloDivs.length; .....
So, it works for all the recent version of browsers but not for IE6. There is still about a 10% market share who are still using IE6. What is the workaround for this browser support?
If i were to print the variable len in IE6 says that is 0 and if i print helloDivs, it says it is an object as if helloDivs is a variable that contains an object but not an array of objects.