Q: write a XHTML document that shows the reasult of the color survey. The document should contain a form with radio buttons that allows users to vote for their favorite color. one of the colors should be selected as a default. Then document should also contain a table showing various colors and the corresponding percentages of votes for each color. (Eeach row should be displayed in the color to which it is referring. ) Use attributes to format width, border and cell spacing for the table.

But I can't use javaScript or PHP. only CSS :sad: :?: help!!!!!

Member Avatar for GreenDay2001

Q: write a XHTML document that shows the reasult of the color survey. The document should contain a form with radio buttons that allows users to vote for their favorite color. one of the colors should be selected as a default. Then document should also contain a table showing various colors and the corresponding percentages of votes for each color. (Eeach row should be displayed in the color to which it is referring. ) Use attributes to format width, border and cell spacing for the table.

But I can't use javaScript or PHP. only CSS :sad: :?: help!!!!!

this is practically not possible...how could you do that with CSS and HTML....they aint scripting languages..they just tell browser how the page and elements should look

this is practically not possible...how could you do that with CSS and HTML....they aint scripting languages..they just tell browser how the page and elements should look

Oh!! ok.. meh welll then how could I do it using Javascript then?

Member Avatar for GreenDay2001

you could do that with javascript, however whatever the user has voted will be stored until the page is opened. once the page is closed everything vanishes...since javascript is not supposed to write files into hard-drives. However you could use cookies...the data will be stored in it. But in both cases the result will be shown of that particular user who is opening that page i mean depending only upon the number of times only he has voted.

so for such purpose server-side scripts such as PHP, ASP etc.. are recommended which could save data from every users.

but i suppose the question assumes that you need to use javascript

for layout you can use CSS, and for vote function you will need to use php with mySQL or asp with MS Acces (server-side scripts with database)

oh.. am going to do that thx

Member Avatar for GreenDay2001

then you need to learn server side script and SQl. i recommend PHP.

SQL for a single vote! :|

Use a single text file, or a text file for each color.

You could do that in PHP, Perl, ASP, etc. But definately: no way without some script sitting on your server.

Is this like, a school/college/university question? If so, they're certainly raising the bar O_O

How could I do this with javascript?

Member Avatar for GreenDay2001

I think you need to learn JavaScript.

Do you know JavaScript?

oK this is what I have been able to do. Can you tell me how to make one of the color as the defult select and how to make the bard for each % (would I just need to creat a image and import it for each)?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>

</head>


<table width='100%' cellpadding=0 cellspacing=4 border=0>
<td><table width=100 cellspacing=0 cellpadding=0 border=0 align=left bgcolor='#001894'><tr><td>
<table width=266 height="243" border=0 cellpadding=0 cellspacing=1>
<tr><td><font color='#FFFFFF' face='verdana,arial' size=1><b>&nbsp;color</b></font></td><td width="81"><font color='#FFFFFF' face='verdana,arial' size=1>&nbsp;<b>%</b></font></td></tr>
<tr bgcolor='#FFFFFF'><td width=111><form name="form1" method="post" action="">
<input name="radiobutton" type="radio" value="radiobutton">
Blue
</form></td>
<td nowrap><font face='verdana,arial' size=1>&nbsp;10%</font></td></tr>
<tr bgcolor='#FFFFFF'><td width=111>
<form name="form2" method="post" action="">
<input name="radiobutton" type="radio" value="radiobutton">
Red
</form></td><td><font face='verdana,arial' size=1>&nbsp;10%</font></td></tr>
<tr bgcolor='#FFFFFF'><td width=111>
<form name="form3" method="post" action="">
<input name="radiobutton" type="radio" value="radiobutton">
Violet
</form></td><td><font face='verdana,arial' size=1>&nbsp;30%</font></td></tr>
<tr bgcolor='#FFFFFF'><td width=111><form name="form4" method="post" action="">
<input name="radiobutton" type="radio" value="radiobutton">
Green
</form></td>
<td><font face='verdana,arial' size=1>&nbsp;50%&nbsp;</font></td></tr></table>
</td></tr></table>
</td></tr></table>
</span></TD>
</TR>
</TABLE>

</TABLE>

that doesn't look like good HTML...elements like "html" and "head" need to contain some data.... you're missing a body (which isn't neccessarily 'wrong', but it's good practice to have one).. and this indicates an illegal construct somewhere :

</TABLE>

</TABLE>

it's never possible to close one table and then another straight away... there's gotta be a cell and a row and preferably a tbody element between a table and any kind of content.

for "showing a percent" (using Javascript):

function setLengthPercent(ident,percent){
  document.getElementById(ident).style.width=percent+"%";
}

that will give you some funky variable-length bars... if you put them in a fixed width element, and float them to the left or to the right; they will be even funky-er.

for a default radio selection...

first of all, give each radio a meaningful value: <input name="radiobutton" type="radio" value="radiobutton"> for all of them isn't going to mean much to you when you want to use the data. it's correct to give them all the same name, but give them each a relevant value.

and then, to set a default:

<input name="radiobutton" type="radio" value="something_relevant" checked="yes">

function setLengthPercent(ident,percent){
document.getElementById(ident).style.width=percent+"%";
}

I dont understand where should I put this?

prefererably between some script tags in your markup somewhere, or in a linked javascript file... even better, you could put it in a handy library of JavaScript functions for graphing things.... but only if you have NOTHING better to do.

As vishesh said; you should probably learn the basics of JavaScript and the HTML DOM.... W3C sites are helpful to begin with:

http://www.w3schools.com/htmldom/default.asp
http://www.w3schools.com/js/default.asp
http://www.w3schools.com/js/js_obj_htmldom.asp

read through those tutorials in order (for each one, keep clicking the 'next' button until you think you know it, or you hit the end).

occasionally, when a tutorial says "try it yourself", give it a try (you can do it on the site).

once you know what that bit of script does (which you will) you will know how to use it, and hopefully where to put it...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.