PDA

View Full Version : radio buttons not working.



ShadowIce
10-29-2009, 09:45 PM
Hi all. I'm having some trouble w/ my radiobutton code and i dont know why. for instance if i select yes for the 1st radio button, and no for the 2nd, instead of doing what it should do for no, it gets rid of w/e it did for yes.. also, if i enter something into the 1st box, and select another radio button, it deletes w/e is in all boxes...

ShadowIce
10-29-2009, 09:46 PM
<html>
<head><title>So you want to make a website?</title></head>
<body>
<script>
var lvl=0;
var cssbgc=0;
var ischecked=0;
var isgroup1=0;
var isgroup2=0;

function get_funcs(lvl){
if(lvl == "Easy"){
a='<hr>\n';
a+='<h1>Website Controls</h1>\n';
a+='Do you want to add a title to your website?<br>\n';
a+='Yes <input onclick="checkchecks()" type="radio" name="group1" value="Yes"> No<input onclick="checkchecks()" type="radio" name="group1" value="No"><br><br>\n';
a+='<div id="websitep">- Does not want website title</div><br>\n';
a+='Do you want to add a background image to your website?<br>\n';
a+='Yes <input onclick="checkchecks()" type="radio" name="group2" value="Yes1"> No<input onclick="checkchecks()" type="radio" name="group2" value="No1"><br><br>\n';
a+='<div id="websiteq">- Does not want website background</div><br>\n';
a+='Your Website scripts:<br><input name="websitescripts" type="text" size="30"> <a href="javascript:answerq(\'websitescripts\');">Help?</a><br>\n';
a+='<br>Your website content (this will appear inbetween &lt;body&gt;&lt;/body&gt;)<br>This can be done for you if you wish: <a href="javascript:answerq(\'webcontent\');">Help?</a><br><textarea rows="15" cols="45" id="websitecontent" name="websitecontent"></textarea><br>\n';
a+='<input type="button" value="Submit" name="sub1" id="sub1" onClick="checkconts(lvl)"><br>\n';
a+='<h1>Your Website</h1><hr>\n';
a+='<textarea rows="15" cols="45" id="websitelvl" name="websitelvl"></textarea>\n';

document.getElementById("websitecontrols").innerHTML = a;

}else if(lvl == "Medium"){

a='<hr>\n';
a+='<h1>Website Controls</h1>\n';
a+='<table>\n';
a+='<tr><td>\n';
a+='Your Website background picture (if any):<br><input name="webback" type="file" size="30"> <a href="javascript:answerq(\'webback\');">Help?</a><br>\n';
a+='Your Website scripts:<br><input name="websitescripts" type="text" size="30"> <a href="javascript:answerq(\'websitescripts\');">Help?</a><br>\n';
a+='Do you want a website background color using css?<br><br>Yes<input onclick="check()" type="checkbox" value="Yes" id="group1" name="group1">&nbsp;No<input onclick="check()" type="checkbox" value="No" id="group1" name="group1"><br>\n<div id="cssbc"></div>\n';
a+='<br>Your website content (this will appear inbetween &lt;body&gt;&lt;/body&gt;)<br>This can be done for you if you wish: <a href="javascript:answerq(\'webcontent\');">Help?</a><br><textarea rows="15" cols="45" id="websitecontent" name="websitecontent"></textarea><br>\n';
a+='<input type="button" value="Submit" name="sub1" id="sub1" onClick="checkconts(lvl)"><br>\n';
a+='</td></tr>\n';
a+='</table>\n';
a+='<h1>Your Website</h1><hr>\n';
a+='<textarea rows="15" cols="45" id="websitelvl" name="websitelvl"></textarea>\n';

document.getElementById("websitecontrols").innerHTML = a;

}
}

function checkchecks(){

for (i=0; i<document.forms.radioform.group1.length; i++){

if(i == 0 && document.forms.radioform.group1[i].checked == true){

ischecked = 1;

isgroup1 = 1;

isgroup2 = 0;

}else if(i == 1 && document.forms.radioform.group1[i].checked == true){

ischecked = 0;

isgroup1 = 0;

isgroup2 = 0;

}

}

for (i=0; i<document.forms.radioform.group2.length; i++){

if(i == 0 && document.forms.radioform.group2[i].checked == true){

ischecked = 1;

isgroup1 = 0;

isgroup2 = 1;


}else if(i == 1 && document.forms.radioform.group2[i].checked == true){

ischecked = 0;

isgroup1 = 0;

isgroup2 = 0;

}

}

if(isgroup1 == 1){

alert('Make SURE this option is what you want. If you select another option after entering data, it will erase your data...');

a='Your Website Title:<br><input name="webtitle" type="text" size="30"> <a href="javascript:answerq(\'webtitle\');">Help?</a><br>\n';
document.getElementById("websitep").innerHTML = a;

}else{

alert('Make SURE this option is what you want. If you select another option after entering data, it will erase your data...');

a='- Does not want website title<br>\n';
document.getElementById("websitep").innerHTML = a;

}

if(isgroup2 == 1){

alert('Make SURE this option is what you want. If you select another option after entering data, it will erase your data...');

b='Your Website background picture (if any):<br><input name="webback" type="file" size="30"> <a href="javascript:answerq(\'webback\');">Help?</a><br>\n';
document.getElementById("websiteq").innerHTML = b;

}else{

alert('Make SURE this option is what you want. If you select another option after entering data, it will erase your data...');

a='- Does not want website background image<br>\n';
document.getElementById("websiteq").innerHTML = b;

}

alert('isgroup1:'+isgroup1+'|'+'isgroup2:'+isgroup2+'');

}

function check(){

for (i=0; i<document.forms.radioform.website.length; i++){

if(document.forms.radioform.website[i].checked == true){

alert('Make SURE this option is what you want. If you select another option after entering data, it will erase your data...');

if(i == 0 && document.forms.radioform.website[1].checked == true){

cssbgc = 0;
document.forms.radioform.website[1].checked = false;

}else if(i == 1 && document.forms.radioform.website[0].checked == true){

cssbgc = 1;
document.forms.radioform.website[0].checked = false;

}
}
}

if(cssbgc == 0){

alert('ok then');

}else if(cssbgc == 1){

document.getElementById("cssbc").innerHTML = "";

}

}

function preview_website(){

if(document.forms.radioform.websitecontent.value != ""){

alert('Previewing your website...');

a='<center><h1>Website Preview<\/h1><\/center>\n<br><br>\n';
a+=document.forms.radioform.websitecontent.value+'\n';

document.write(a);

}

}

function previewconts(){

if(document.forms.radioform.websitecontent.value != "" || document.forms.radioform.webtitle.value != "" || document.forms.radioform.webback.value != "" || document.forms.radioform.weblvl.value != ""){

preview_website(lvl);

}else{

alert('Please enter something into the box before continuing...');

}

}

function checkconts(lvl){

if(document.forms.radioform.websitecontent == null || document.forms.radioform.websitecontent == null || document.forms.radioform.webtitle == null || document.forms.radioform.webback == null || document.forms.radioform.weblvl == null){

alert('Please select an option 1st...');

}else if(document.forms.radioform.websitecontent.value == null || document.forms.radioform.websitecontent.value == null || document.forms.radioform.webtitle.value == null || document.forms.radioform.webback.value == null || document.forms.radioform.weblvl.value == null){

alert('Please enter something into the box before continuing...');

}else{

a=document.forms.radioform.websitelvl.value = website(lvl);

document.getElementById('websitecontent').innerHTML = a;

}

}

function get_option(which){

if(which == "webtitle"){

return document.radioform.webtitle.value;

}else if(which == "webback"){

return document.radioform.webback.value;

}else if(which == "websitecontent"){

return document.radioform.websitecontent.value;

}else if(which == "websitescripts"){

return document.radioform.websitescripts.value;

}

}

function answerq(divname){

if(divname == "webtitle"){

alert('This is where you enter the name of your website that appears in the top left corner of your web browser.');

}else if(divname == "webback"){

alert('This is where you enter a background image link or a select a picture from your hard drive (IE: When selected you will see something like C:/mypics/pic.jpg appear in the box).');

}else if(divname == "webcontent"){

alert('this is where you enter what you want to appear on the page (this can be done for you if you wish).');

}else if(divname == "websitescripts"){

alert('This is where you enter any file locations to your script file(s).');

}

}

function website(lvl){

if(lvl == "Easy"){

a = "<html>\n";
a += "<head><title>"+get_option('webtitle')+"</title></head>\n";
if(document.forms.radioform.webback.value == ""){
a += "<body>\n";
}else{
a += "<body background=\""+get_option('webback')+"\">\n";
}
if(document.forms.radioform.websitecontent.value != ""){
a += get_option('websitecontent')+"\n";
a += "</body>\n";
}else{
a += "</body>\n";
}
a += "</html>\n";

}

return a;

}

function callcontrols(lvl){

if(lvl == "Easy" || lvl == "Medium" || lvl=="Hard" || lvl == "Extreme"){

get_funcs(lvl);

}else{

document.getElementById("websitecontrols").innerHTML = "NO!";

}

}

function getwebsite(lvl){

if(lvl == "Easy" || lvl == "Medium" || lvl == "Hard" || lvl == "Extreme"){

callcontrols(lvl);

}

}

function get_radio_value()
{
for (var i=0; i < document.radioform.website.length; i++)
{
if (document.radioform.website[i].checked)
{

var rad_val = document.radioform.website[i].value;

getwebsite(rad_val);

}

}

lvl = rad_val;

alert(lvl);

}
</script>
<center>
<h1>So you want to build a website?</h1><br>
Easy - HTML Website<br>
Medium - HTML / JavaScript / CSS Website<br>
Hard - HTML / JavaScript / CSS / PHP Website<br>
Extreme - HTML / Encrypted HTML / JavaScript / Encrypted JavaScript / CSS / PHP Website<br><br>
You have four choices: <br>
<form name="radioform">
Step 1:<br>Choose an option<br><br>
Easy<input type="radio" onclick="get_radio_value()" name="website" value="Easy">Medium<input onclick="get_radio_value()" type="radio" name="website" value="Medium">Hard<input onclick="get_radio_value()" type="radio" name="website" value="Hard">Extreme<input onclick="get_radio_value()" type="radio" name="website" value="Extreme"><br><br>
<div id="websitecontrols"></div>
</form>
</center>
</body>
</html>

ShadowIce
10-29-2009, 09:46 PM
The functions you are looking at are checkchecks() and checkconts().

here's the functions:

checkchecks():


function checkchecks(){

for (i=0; i<document.forms.radioform.group1.length; i++){

if(i == 0 && document.forms.radioform.group1[i].checked == true){

ischecked = 1;

isgroup1 = 1;

isgroup2 = 0;

}else if(i == 1 && document.forms.radioform.group1[i].checked == true){

ischecked = 0;

isgroup1 = 0;

isgroup2 = 0;

}

}

for (i=0; i<document.forms.radioform.group2.length; i++){

if(i == 0 && document.forms.radioform.group2[i].checked == true){

ischecked = 1;

isgroup1 = 0;

isgroup2 = 1;


}else if(i == 1 && document.forms.radioform.group2[i].checked == true){

ischecked = 0;

isgroup1 = 0;

isgroup2 = 0;

}

}

if(isgroup1 == 1){

alert('Make SURE this option is what you want. If you select another option after entering data, it will erase your data...');

a='Your Website Title:<br><input name="webtitle" type="text" size="30"> <a href="javascript:answerq(\'webtitle\');">Help?</a><br>\n';
document.getElementById("websitep").innerHTML = a;

}else{

alert('Make SURE this option is what you want. If you select another option after entering data, it will erase your data...');

a='- Does not want website title<br>\n';
document.getElementById("websitep").innerHTML = a;

}

if(isgroup2 == 1){

alert('Make SURE this option is what you want. If you select another option after entering data, it will erase your data...');

b='Your Website background picture (if any):<br><input name="webback" type="file" size="30"> <a href="javascript:answerq(\'webback\');">Help?</a><br>\n';
document.getElementById("websiteq").innerHTML = b;

}else{

alert('Make SURE this option is what you want. If you select another option after entering data, it will erase your data...');

a='- Does not want website background image<br>\n';
document.getElementById("websiteq").innerHTML = b;

}

alert('isgroup1:'+isgroup1+'|'+'isgroup2:'+isgroup2+'');

}

checkconts():


function checkconts(lvl){

if(document.forms.radioform.websitecontent == null || document.forms.radioform.websitecontent == null || document.forms.radioform.webtitle == null || document.forms.radioform.webback == null || document.forms.radioform.weblvl == null){

alert('Please select an option 1st...');

}else if(document.forms.radioform.websitecontent.value == null || document.forms.radioform.websitecontent.value == null || document.forms.radioform.webtitle.value == null || document.forms.radioform.webback.value == null || document.forms.radioform.weblvl.value == null){

alert('Please enter something into the box before continuing...');

}else{

a=document.forms.radioform.websitelvl.value = website(lvl);

document.getElementById('websitecontent').innerHTML = a;

}

}

ShadowIce
10-29-2009, 09:47 PM
Sorry for the triple and last posts, i would have put it into 1 post, but the forum wouldnt let me..... ><

ShadowIce
10-30-2009, 12:04 PM
*bump* i waited 24 hours. so plz dont flame.