Showing posts with label CSS. Show all posts
Showing posts with label CSS. Show all posts

Wednesday 16 September 2009

A JS/CSS based star rating system for web pages

I was working on a project tonight that needed a "star" rating system and I had one from a while ago that you may find useful.

It works like this.

I have an image that is 20px wide and 40px deep
In the top 20x20px I have an empty star
In the bottom 20x20px I have a selected star like this




If I place this image as a background in a block type element sized 20x20px with a CSS style of background-position: left top; the user will be presented with the empty star. If on the other hand I position it with the CSS of background-position: left bottom; you will see the selected star.

So all I need to do now is create an HTML
(1) that has a hidden field for me to store the value that will relate to the number of stars selected
(2) that has a table were each cell is sized to be 20x20px
(3) where each cell has CSS with a background-image of my star picture
(4) where each cell as an onmouseover event that changes the css so that the background image's css is changed to be the bottom portion of the background image.

If it all works you will get something like this (sorry it is off site.. but blogger wouldnt play ball with the JS)

The code for the page in the link above looks like this . feel free to take and use as you see fit.. however if you do drop me a comment.. I like to feel i am being useful ;-)

<html>
<head>
<style>
.star
{
background-image: url(star_rating.gif);
background-position: top left;
width: 20px;
height: 20px;
cursor: pointer;
}
</style>
<script = 'javascript'>
function star(a)
{
// reset all stars to blank
for(var t=1;t<=5;t++)
{
document.getElementById(t+"star").style.backgroundPosition="left top";
}
// Set new value in hidden field
document.forms[0].likeem.value=a;
// Set new value for display
for(var t=1;t<=parseInt(a);t++)
{
document.getElementById(t+"star").style.backgroundPosition="left bottom";
}
}
</script>
</head>
<body onload="star(3)">
<form>
This field below normaly be hidden <br>
<input type='text' id='likeem' name='likeem' value=""><br>
Now move your mouse over the stars below</br>

<table cellspacing='0' cellpadding='0' border='0'>
<tr>
<td id='1star' class='star' onmouseover= "star(1)"></td>
<td id='2star' class='star' onmouseover= "star(2)"></td>
<td id='3star' class='star' onmouseover= "star(3)"></td>
<td id='4star' class='star' onmouseover= "star(4)"></td>
<td id='5star' class='star' onmouseover= "star(5)"></td>
</tr>
</table>

</form>
</body>
</html>

Wednesday 21 January 2009

My First V8.5.0 project - Getting a decent floating layout

I have been fiddling with a variety of layouts of late and I really wanted a fluid 2 column plus header and footer arrangment, like the one on the left (but not in those colours) And I did not want to involve tables. So I tried I floated things left and right, up and down, in and out, but could not get it just the way I wanted it without going all position: absolute. the main problem being floating the footer to the bottom.

It seemed that the only way to do this was with absolute positioning, which I wanted to avoid if at all possible!

Then I came across this article by Shaun Inman and my problem was solved! He describes the solution much better than I can so I advise you to go have a look see if such things make you moist.

He has a really simple CSS and JS resolution to the problem so I copied it down and into a NSF page to see if it would work and it does!! Wonderfully fluid centered [div]s with a header at the top and a footer at the bottom ..(see below) ... Yippee ... Just what I wanted. Now if I can just get it to work in xPages which is being somewhat of a puzzle, but I shall continue on regardless. More tomorrow.

Posted by Picasa

Sunday 30 November 2008

Two useful tools for IE web devs

I was joined by "Wild" Bill Buchan this weekend for a spot of iSeries Geekery, Guinness,champ and Harbour Bar frolicary but more of that later.

Whilst Bill was saying "oh my life" and having pointer size issues. I did a couple of wee changes to some CSS on an app that was having IE issues. I am sure you know the type, looks fine in FF, Safari, Opera but goes tits up in IE. Now I have been using 2 wee tools that helps me with such things. Bill had not come either tool and suggested I throw it out to the web dev horde.

I am as I am sure you all are users of Firebug in FF and long for a similar product for IE. Well Companion.JS from the very nice people at MyDebugBar is a free product that "faces" the Microsoft Script Debugger in a very Firebug way. Full install instructions can be found at the link above, oh and did i mention it is free :-) we here at DYM like free! Free is good!

The other tool comes from the same crowd and is called "My Debug Bar" and although you have to pay for it, you can download it try before you buy.
Summary of features
* Menu to customize the DebugBar and check updates.
* Toggle the Development bar
* Alert on javascript errors
* Send page screenshot by email
* Color picker
* Resize IE window
* Zoom page
* View source code
* View MSHTML integrated ActiveX source code
* View HTML DOM Tree
* View original ad interpreted source code
* View tab attributes
* Edit tab attributes
* View HTTP and HTTPS headers
* View page cookies
* Validate html code for main page and frames/iframes
* List all javascript functions
* View javascript function code
* Execute javascript code in the currently loaded page
* Get information about currently loaded page


Now it doesn't debug JS (Companion.JS does that) but it does have a real whiz bang DOM inspector.. you can drag the inspector onto the browser pane point it at an element and get all the details about it. The CSS the element has (and has inherited)
for finding the source of those annoying glitches that make your web page look like shite it is invaluable. The HTML checker is pretty cool too and I use it frequently

Like I said previously you have to pay for MyDebugbar and it is 59 euros and if you do a lot of IE development this tool will pay for itself very quickly.

Sunday 20 April 2008

Aligning Checkboxes in a form for the web

There has to be an easier way of doing this!
When you create a checkbox, the CSS style parms do not work all that well and you get a ghastly thing like this:Fig1 No styling other that saying there are 3 columns.

What i want is a 5px gap between the box and the label and the label to be a set length.
I have fiddled and footered about with the object trying things like
"[p class='cb1']Customer[p]|Customer" for the available text values in the CB list.
But no matter what I select the list always comes out all higgleded piggly.

Eventually I gave in trying to be smart and I fudged it by doing this

1. Stash the list of available options in an NSF wide Profile Doc Field called SysConfig
2. Place a CB field on the form but Hide it From the Web
3. Place an empty [div] with an id = 'ooi' on the form where I want the Check boxes to appear
3. I ensure the form has "create HTML for all fields"
4. I stick this code on the page up near the top
[script language='javascript']var OOI = '[Computed Text]';[/scrip]
where Computed text =@getprofilefield("SysConfig";"OrgOfIdea");
5. I create a function createOOI() in the JS Header and then call it on the onLoad event of the page
6. The createOOI function looks like this
function createOOI()
{
var OOIa = OOI.split(";");
target = document.getElementById("ooi");
tHTML = "[table]";
ct=1;
for(t=0;t LT OOIa.length;t++)
{
if(ct==4)

{
tHTML=tHTML+"[/tr]"
ct=1;
}
if(ct==1)
{
tHTML=tHTML+"[tr]"
}
tHTML = tHTML+"[td class='cb3'][input style='margin-right:5px;' type='checkbox' name='ooicb' value='"+OOIa[t]+"']"+OOIa[t]+"[/td]"
ct=ct+1

}
tHTML = tHTML+"[/table]";
target.innerHTML = tHTML;
}

07. Place a pseudo class of .cb3 into the CSS file for this form with the width, font, spacing etc set

This results in a nicely formatted table of Checkboxes like this.

Doing it this way means that you have a field with a name OOICB which does not actually appear on the form so you have to do two extra things in the JS.

01. Move the selected boxes from the OOICB field to your hidden parent CB field as a ";" delimited list
02. Test your hidden Parent CB field on page load event after the OOICB has been added to the dom to check those fields that have been selected already.

This is a PAIN and there has to be an easier way but i am buggered if I can see what it is.




Tuesday 8 April 2008

Creating a Cascading outline Lists in CSS

Ever wanted an easy way to do indented lists with varying numbering schemes
An easy way to do this is with CSS

[style type="text/css"&gt]
ol {
list-style-type: upper-roman;
}
ol ol {
padding-left:2em;
list-style-type: upper-alpha;
}
ol ol ol {
list-style-type: decimal;
}
ol ol ol ol {
list-style-type: lower-alpha;
}
ol ol ol ol ol {
list-style-type: lower-roman;
}
[/style]
If you use use style and then have an html list like this will result in it being formatted like this
[ol style="font-size:xx-small"]
[li] Major outline item.
[ol style="font-size:xx-small"][li] Next level down.
[ol style="font-size:xx-small"][li] And a first point about that.
[ol style="font-size:xx-small"][li] The first point has a note.
[ol style="font-size:xx-small"][li] And that note has two notes.[/li]
[li] Ending with this.
[/li][/ol]
[/li][/ol]
[li] The second point comes along.
[ol style="font-size:xx-small"][li] The second point needs elaboration.
[li] Elaboration is well broken up.[/li]
[li] And shouldn’t go on forever.
[/li][/ol]
[/li][/ol]
[li]Close big!
[ol style="font-size:xx-small"][li]Make the point.[/li][/ol]
[/li][/ol]
[/li]
[li] Big bugs have little bugs
[ol style="font-size:xx-small"][li] Upon their back to bite them.
[ol style="font-size:xx-small"][li] Little bugs have littler bugs.
[ol style="font-size:xx-small"][li] And so, ad infinitum.
[/li][/ol]
[/li][/ol]
[/li][/ol]
[li] The fun can go on forever!
[/li]
[/ol]

(needless to say change the [] to the right sort of brackets)
Will result in it being formatted like this


  • Major outline item.
    1. Next level down.
      1. And a first point about that.
        1. The first point has a note.
          1. And that note has two notes.
          2. Ending with this
      2. The second point comes along.
        1. The second point needs elaboration.
        2. Elaboration is well broken up.
        3. And shouldn’t go on forever.
    2. Close big!
      1. Make the point.
  • Big bugs have little bugs
    1. Upon their back to bite them.
      1. Little bugs have littler bugs.
        1. And so, ad infinitum.
  • The fun can go on forever!
  • Disqus for Domi-No-Yes-Maybe