Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeOur CommunityOur CommunityGeneral Discuss...General Discuss...How to get basic javascript working?How to get basic javascript working?
Previous
 
Next
New Post
1/23/2009 1:41 AM
 

I've been trying to get this working for a few days now but with no luck.

The code is:

<script type="text/javascript">
/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: Alan Gruskoff | http://www.performantsystems.com/ */

function anyCheck(form) {
var total = 0;
var max = form.ckbox.length;
for (var idx = 0; idx < max; idx++) {
if (eval("document.playlist.ckbox[" + idx + "].checked") == true) {
    total += 1;
   }
}
al*rt("You selected " + total + " boxes.");
}
</script>
<form name="playlist" method="post">
    1<input type="checkbox" name="ckbox" /> <br />
    2<input type="checkbox" name="ckbox" /> <br />
    3<input type="checkbox" name="ckbox" /> <br />
    4<input type="checkbox" name="ckbox" /> <br />
    5<input type="checkbox" name="ckbox" /> <br />
    6<input type="checkbox" name="ckbox" /> <br />
    7<input type="checkbox" name="ckbox" /> <br />
    8<input type="checkbox" name="ckbox" /> <br />
    9<input type="checkbox" name="ckbox" />
    <p><input type="button" onClick="anyCheck(this.form)" value="Count Checkboxes" /></p>
</form>

Of course change '*' to 'e' at the end of the javascript as DNN forums don't like the Al*rt word!

 

It works fine just as itself in a small html file... but when used in a DNN website I just can't get it working.  I am new to using Javascript too so this is just a step to learning and understanding a bit more (though I am working towards performing a task).

I've tried separating the javascript from the form - using it in the module header, page header and also by linking it to an external js file with the code from these spots too - all failing to work.

What am I doing wrong and what do I need to do to get this working?

Thanks

 
New Post
1/23/2009 1:55 AM
 

David-
You cannot place a form into a DNN page because DNN already dynamically generates a form for the page -- your form ends up being nested inside of DNN's form (that's a no-no, in case you were wondering).  The end effect is that DNN's form will work, yours will not.

Since you're not relying on your form tag to actually post anything to the server, try changing your HTML code to use a DIV instead of a form.

-mamlin

 


esmamlin atxgeek.me
 
New Post
1/23/2009 2:08 AM
 

Hi mamlin

Thanks for the quick reply.

Were you meaning to use:

<div name="playlist" method="post">
  ...

</div>

This is what I tried but had no luck.

I hadn't realised DNN automatically puts pages in a form as I'm only just starting to work with this sort of thing.

Cheers

 

 
New Post
1/23/2009 2:35 AM
 

DavidToohey wrote
Hi mamlin
Thanks for the quick reply.  Were you meaning to use:

 

  ...

 

I hadn't realised DNN automatically puts pages in a form as I'm only just starting to work with this sort of thing.
Cheers

David-
First, you don't need the "method='post'" in a DIV tag -- that's only for form tags. 

Second, unless you want to use your function for a number of different checkbox collections, you don't need to pass a reference to your HTML element (calling the JS function with "this.form" as a parameter).  You can simplify things slightly by defining the element in the JS function itself -- use "form = document.getElementById('playlist')" to get the element reference at the start of the function.  Personally I'd also use a different JS variable name than 'form' as I consider using HTML tagnames as variable names to be bad...form.  (heh-heh.  that's a late-night HTML joke...)

I'm off to bed right now otherwise I'd play with the code a bit to see if I could quickly post a working variation.  There's no reason you shouldn't be able to do what you want by adding the code to a Text/HTML module (using the "SOURCE" view option, of course).  Now that you've removed the extra "form" tag, all you need is to properly get a reference to the container element with ID = "playlist".

Good luck and keep posting back to the thread if you continue to have issues-
-mamlin


esmamlin atxgeek.me
 
New Post
1/23/2009 2:39 AM
 

Oh, if you're still new to javascript then be aware that it is case-sensitive (or else you'll quickly become a very frustrated JS coder...)


esmamlin atxgeek.me
 
Previous
 
Next
HomeHomeOur CommunityOur CommunityGeneral Discuss...General Discuss...How to get basic javascript working?How to get basic javascript working?


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out