javascript help

Status
Not open for further replies.

Kracov

Ars Praetorian
413
I need to know how to use classes and containers. Specifically this part, which I do not know where to put or what the "id_of_container" should be:

Code:
"To specify the name of this form element, give the Starry widget a name property."
	<script>
	 new Starry('id_of_container', {name:"starry"}
	</script>

Which is from here: http://www.htmldrive.net/items/show/623 ... m-Widget-2
 
Javascript doesn't have classes. The example you're looking at uses Prototype.js which emulates classed-based languages.

The container in this example is an DIV HTML element "Starry" creates to contain the stars. "id_of_container" is whatever you want to name it.

Also, the example you posted from the site has a syntax error:

Code:
	 new Starry('id_of_container', {name:"starry"}

should be

Code:
	 new Starry('id_of_container', {name:"starry"});
 

Kracov

Ars Praetorian
413
Can you help me with it? I still can't get it working even with the fixed syntax. What I'm trying to do is get the star rating to appear below the Doom Giant image/text

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head>

	<script type="text/javascript" src="http://kracov.org/site/stars/prototype.lite.js"></script>
	  
	<script type="text/javascript" src="http://kracov.org/site/stars/stars.js"></script>
	 
	<link rel="stylesheet" href="http://kracov.org/site/stars/stars.css" type="text/css" />

  <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">

  <meta name="Keywords" content="kracov,wolf,art,graphics,games,doom,diablo,pixel,wallpaper,characters,scenery,dark,horror,chyderok,warrior,wolf,cyborg,demon,sinjid,yordrim,behemoth,wolverine,hulk,juggernaut,venom">
  
  <meta name="description" content="Kracov's Art and Graphics"><title>Kracov's Art</title>

  <link rel="icon" href="http://kracov.org/site/siteicon.png" type="image/x-icon">

  <link rel="shortcut icon" href="http://kracov.org/site/siteicon.png" type="image/x-icon">

  <style>
BODY { color: rgb(255, 255, 255); background-color: rgb(42, 42, 42); background-image: url(http://kracov.org/site/backpaint.jpg);
background-repeat: no-repeat;
background-attachment: fixed;
background-position: top center;
}
  </style></head>
	<script>
	 new Starry('starry', {name:"starry"});
	</script>
<body style="color: rgb(255, 255, 255); background-color: rgb(47, 47, 47);" alink="#000099" link="#414141" vlink="#414141">

<div style="text-align: center;"><img style="width: 88px; height: 39px;" alt="kracov's art" src="http://kracov.org/site/art1.png"><br>

</div>

<div style="text-align: center;">
<div style="text-align: center;"></div>

<table style="width: 800px; text-align: left; margin-left: auto; margin-right: auto;" border="0" cellpadding="6" cellspacing="14">

  <tbody>

    <tr>

      <td style="text-align: center; font-family: Verdana;"><small><a href="http://kracov.org/art/doomgiantx.jpg"><img style="border: 0px solid ; width: 75px; height: 95px;" alt="doom giant" src="http://kracov.org/art/doomgiantxa.jpg"></a><br>

Doom Giant</small>
	<input type="hidden" name="starry" value="0" /></td>
 
Kracov":ancvqrcd said:
Can you help me with it? I still can't get it working even with the fixed syntax. What I'm trying to do is get the star rating to appear below the Doom Giant image/text

Couple of things first:

  • Avoid using tables to layout your web page. Use CSS.
  • Avoid inline CSS (putting the style inside the html elements). You want to keep your content and design separated.

The script
Code:
<script>
   new Starry('starry', {name:"starry"});
</script>

creates the input for you. You don't need the hidden input at the bottom.

Generally speaking, HTML elements appear on the page in the order you place them. To move the stars below your image, simply move "Starry" script below the HTML for the image.
 
Kracov":3qpgpq6v said:
Ah I see. It's actually for a gallery of images, and I need to add a rating below each image, which is why I thought the hidden input is for each image.

Copy that script and paste it under every image you want to use it with. Just be sure to give them all unique ids/names.

Kracov":3qpgpq6v said:
I have been trying to look for a css table tutorial that includes how to add URLs and captions.

Don't use tables for this. Check out the CSS "float" property. Here's an example:

Code:
<!DOCTYPE html>
<html>
    <head>
        <title>Float Left</title>
        <script type="text/javascript" src="http://kracov.org/site/stars/prototype.lite.js"></script>
        <script type="text/javascript" src="http://kracov.org/site/stars/stars.js"></script>
        <style>
            #gallery {
                width: 800px;
            }
            
            .imageRater	{
                float: left;
                margin: 5px;
                padding: 5px;
                text-align: center;
                border: 1px solid #999;
            }
        </style>
    </head>
    
    <body>
        
        <div id="gallery">
            <div class="imageRater">
                <img alt="doom giant" src="http://kracov.org/art/doomgiantxa.jpg" />
                <script>new Starry('starry');</script>
            </div>
            <div class="imageRater">
                <img alt="doom giant" src="http://kracov.org/art/doomgiantxa.jpg" />
                <script>new Starry('starry2');</script>
            </div>
            <div class="imageRater">
                <img alt="doom giant" src="http://kracov.org/art/doomgiantxa.jpg" />
                <script>new Starry('starry3');</script>
            </div>
            <div class="imageRater">
                <img alt="doom giant" src="http://kracov.org/art/doomgiantxa.jpg" />
                <script>new Starry('starry4');</script>
            </div>
            <div class="imageRater">
                <img alt="doom giant" src="http://kracov.org/art/doomgiantxa.jpg" />
                <script>new Starry('starry5');</script>
            </div>
            <div class="imageRater">
                <img alt="doom giant" src="http://kracov.org/art/doomgiantxa.jpg" />
                <script>new Starry('starry6');</script>
            </div>
            <div class="imageRater">
                <img alt="doom giant" src="http://kracov.org/art/doomgiantxa.jpg" />
                <script>new Starry('starry7');</script>
            </div>
            <div class="imageRater">
                <img alt="doom giant" src="http://kracov.org/art/doomgiantxa.jpg" />
                <script>new Starry('starry8');</script>
            </div>
            <div class="imageRater">
                <img alt="doom giant" src="http://kracov.org/art/doomgiantxa.jpg" />
                <script>new Starry('starry9');</script>
            </div>
        </div>

    </body>
</html>
 
I just tried Firebug- no errors or warnings. The image stars.gif is at my site in the same folder as the css files etc. However I checked out the starry Demo, and it works. Here is part of the code that shows a star rating example:

Code:
<fieldset><legend>Setting a custom length</legend>
<script>
	new Starry('custom_length', {name:'customLength', maxLength:12});
</script>					
<pre>&lt;script&gt;
   new Starry('custom_length', {name:'customLength', maxLength:12});
&lt;/script&gt;</pre>
</fieldset>
 
I found an easier rating system- I just need help with linking to the files. I can see the stars but they don't work. It relies on jquery and uses radio buttons. Here are the contents:
jquery.form.js, jquery.js, jquery.MetaData.js, jquery.rating.css, jquery.rating.js, jquery.rating.pack.js

from link http://www.fyneworks.com/jquery/star-rating/

some of the code- i'm assuming that i need to link to more of the files
Code:
    <head>
        <title>Float Left</title>
        <script type="text/javascript" src="http://kracov.org/site/stars2/jquery.js"></script>
        <script type="text/javascript" src="http://kracov.org/site/stars2/jquery.rating.js"></script>
	<link rel="stylesheet" href="http://kracov.org/site/stars2/jquery.rating.css" type="text/css" />
 
Status
Not open for further replies.