Strike Force Heroes 2
The explosive sequel to the hit game Strike Force Heroes!
3.96 / 5.00 8,979 ViewsObsolescence
Defeat the enormous mechanical beasts--and become one of them.
4.02 / 5.00 43,353 ViewsFor anybody that knows js absolutely refuses to work for me... here are some snippets if someone would kindly debug them.
$("#ssub").click(function() {
var myForm = document.getElementByID('shrimp');
var tag = myForm.getElementsByTagName('select');
var count = 0;
for (var i = 0, len = tag.length; i < len; i++) {
count++
}
alert(count);
})
... and the corresponding HTML:
<form id="shrimp">
<div id="sblc">
<div class="opt">
<select>
<option>Domestic</option>
<option>Tiger</option>
<option>Peeled Raw</option>
<option>Cooked Peeled Tail On<option>
</select>
<select>
<option>1 lbs</option>
<option>2 lbs</option>
<option>3 lbs</option>
</select>
</div>
</div>
<div>
<button id="snew" type="button">Add Order</button>
<button id="ssub" type="button">Enter Order</button>
</div>
</form>
</div>
Thank you for any assistance.
I need a break now :/
Since I was oh so clear... I'm attempting to find the number of select boxes in the given form. i want to cant them and throw the data to a larger form.
Sorry about that.
The only thing I can seem to see is that
for (var i = 0<strong>,</strong> len = tag.length; i < len; i++) {
should be
for (var i = 0<strong>;</strong> len = tag.length; i < len; i++) {
This BBS uses the code tags right?
"If loving Python is crazy then I don't want to be sane." -Diki
At 4/4/12 08:28 PM, pirateplatypus wrote:
D'oh! the strong tag doesn't seem to work when nested in a code tag. The problem I was trying to suggest was that in your for loop from the JS you used a comma instead of a semi-colon after declaring i.
"If loving Python is crazy then I don't want to be sane." -Diki
Well, first off, why are you mixing jQuery with document.getElementById?
However to do what you want is trivial:
var num = jQuery('.opt select').length;
Doing jQuery('.opt select') will return a jQuery object of all <select> containers inside a container with a class of "opt" (which is the <div> that you wrapped your <select> containers in).
Then the length property does what it implies; returns the number of objects found.
Note: You should give that <div> an id to reference with instead of a class; it's much faster.
At 4/4/12 08:28 PM, pirateplatypus wrote: The only thing I can seem to see is that
for (var i = 0, len = tag.length; i < len; i++) {
should be
for (var i = 0; len = tag.length; i < len; i++) {
This BBS uses the code tags right?
There is nothing wrong with his for loop declaration. It is valid to define more than one variable in a for loop.
Replacing the comma with a semi-colon would actually invalidate the JavaScript and cause errors.
At 4/4/12 08:34 PM, Diki wrote:
There is nothing wrong with his for loop declaration. It is valid to define more than one variable in a for loop.
Replacing the comma with a semi-colon would actually invalidate the JavaScript and cause errors.
D'oh! Thanks for pointing that out. I didn't notice the second variable in there.
"If loving Python is crazy then I don't want to be sane." -Diki
At 4/4/12 08:32 PM, Diki wrote: Well, first off, why are you mixing jQuery with document.getElementById?
However to do what you want is trivial:
var num = jQuery('.opt select').length;
You can test it out here.
Doing jQuery('.opt select') will return a jQuery object of all <select> containers inside a container with a class of "opt" (which is the <div> that you wrapped your <select> containers in).
Then the length property does what it implies; returns the number of objects found.
Note: You should give that <div> an id to reference with instead of a class; it's much faster.
The reason I did it like that is because there will be multiple forms (this being one of them) that will feed to a master form to allocate data in a single $_POST. This is why I attempted to tag a form id. Would the following work:
var num = jQuery('#shrimp select').length;
Also, is the fact that I'm weaving raw JS with jQuery actually be my problem?
Thanks for the responses.