Click to See Complete Forum and Search --> : form option addition problem


catchup
03-21-2003, 02:06 AM
i have a form that has 6 options (options called "car"):

options/values:
red = 3, blue = 4, black = 6

in the same form i have a extra section (options called "car2"):
tinted_windows = 2, no_tint = 0

I set the form up so that either red or blue or black can be selected,
AND that either tinted_windows or no_tint can be selected.
The max points this form can Post has to be 6. How can it be written so that
upon submission JS adds car and car2 together and if > 6 then Total_car=6 ,And if less
than six, Total_car= car+car2 ?

thanks

khalidali63
03-21-2003, 06:18 AM
I take from "options" you are referring to dro down list box.If so then here is how you can get value from a drop down selected value

e.g
var value1 = document.formName.listBoxName.options[document.formName.listBoxName.selectedIndex].value;

get the values from both list boxes and then
if ((value1+value2) >6){
total = 6
}else{
total = value1+value2
}

Hope this points to right direction

Cheers

Khalid

catchup
04-03-2003, 12:18 AM
thank you, actually it is radio buttons, guess i should have mentioned that, sry. I have radio buttons
on the same page as this JS, The 12 radio buttons - 10 of which "name" are all the same, using a
"allowing only one" radio to be selected at one time in both the first group or 10 radios
and the second group or 2 radios. first group has name = wor and second group = wor2, so i'm
trying to add the form wor+wor2 into total.

var data = "";
var itemchecked = false;
function checkRadios() {
var el = document.forms[0].elements;
for(var i = 0 ; i < el.length ; ++i) {
if(el[i].type == "radio") {
var radiogroup = el[el[i].name]; // get the whole set of radio buttons.
for(var j = 0 ; j < radiogroup.length ; ++j) {
if(radiogroup[j].checked) {
itemchecked = true;
break;
}
}
if(!itemchecked) {
alert("Please select where you plan to settle");
if(el[i].focus)
el[i].focus();
return false;
}
}
}

var value1 = parseInt(document.f6.wor[j].value;
var value2 = parseInt(document.f6.wor2[k].value;
if ((value1+value2) >16){
total = 16
}else{
total = value1+value2
}

var sStr = document.location.search;
var val = parseInt(sStr.substring(sStr.indexOf("=")+1,sStr.indexOf(",")));
var sum = parseInt(document.f6.wor[j].value)+((!isNaN(val))?val:0);
if(itemchecked){
data = sStr.substring(sStr.indexOf(","),sStr.length)+ ",(wor="+total)+")";
document.f6.action="Language.htm?wor="+sum+data ;
}
//return true;
}

window.onload = updateRunningScore;
function updateRunningScore(){
var sStr = document.location.search;
val = parseInt(sStr.substring(sStr.indexOf("=")+1,sStr.length));
document.getElementById("currentScore").innerHTML = "Now = "+((!isNaN(val))?val:0);
}

catchup
04-04-2003, 11:34 PM
oh Supreme Master, are you there...

khalidali63
04-05-2003, 12:43 AM
Now if I understood you correctly,take a look at the solution below.


<script type="text/javascript">
function Process (){
var firstRG = document.form1.wor;//forst radio button group array
var secRG = document.form1.wor2;//forst radio button group array
var val1 = 0,val2 = 0,total = 0;
//get value from first group
for(var n=0;n<firstRG.length;n++){
if(firstRG[n].checked){
val1 = parseInt(firstRG[n].value);
break;
}
}

for(var x=0;x<secRG.length;x++){
if(secRG[x].checked){
val2 = parseInt(secRG[x].value);
break;
}
}
total = val1+val2;
alert("value selected from first group = "+val1+
"\nvalue sel;ected from second group = "+val2+
"\n total of 2 values = "+total);
}
</script>
</head>

<body class="body">
<form name="form1" action="" >
Radio Buttons Set A (wor)<br/>
<input type="Radio" name="wor" value="1"/><br/>
<input type="Radio" name="wor" value="2"/><br/>
<input type="Radio" name="wor" value="3"/><br/>
<input type="Radio" name="wor" value="4"/><br/>
<input type="Radio" name="wor" value="5"/><br/>
<input type="Radio" name="wor" value="6"/><br/><br/>
Radio Buttons Set B (wor2)<br/>
<input type="Radio" name="wor2" value="5"/><br/>
<input type="Radio" name="wor2" value="8"/><br/>
<input type="Submit" value="Process" onclick="Process();"/>
</form>


Cheers

Khalid

catchup
04-21-2003, 01:19 AM
hmm... Unterminated String Constant error on line //**



<script type="text/javascript">
function Process (){
var firstRG = document.form1.wor; //first radio button group array
var secRG = document.form1.work; //second radio button group array
var val1 = 0,val2 = 0,total = 0;
//get value from first group
for(var n=0;n<firstRG.length;n++){
if(firstRG[n].checked){
val1 = parseInt(firstRG[n].value);
break;
}
}

for(var x=0;x<secRG.length;x++){
if(secRG[x].checked){
val2 = parseInt(secRG[x].value);
break;
}
}
total = val1+val2;

}

var sStr = document.location.search;
var val = parseInt(sStr.substring(sStr.indexOf("=")+1,sStr.indexOf(",")));
var sum = (+total)+((!isNaN(val))?val:0);
if(itemchecked){
data = sStr.substring(sStr.indexOf(","),sStr.length)+ ",wor="+(+total)"; //**
document.f6.action="Language.htm?wor="+sum+data ;
}
//return true;
}

webby
04-21-2003, 09:57 AM
can't help with the script ...edit...

Moderator's note: Then, since you can't maintain at least a barely civil tongue in your head, you should have kept your nose out of this thread. You've been warned before -- without change on your part. Are you prepared to lose your membership over this kind of talk?

catchup
04-24-2003, 10:26 AM
what could be causing an unterminated string constant error, it is ended by a quote mark at the end of the string ...???

Jona
04-24-2003, 10:32 AM
You're missing a plus sign:

data = sStr.substring(sStr.indexOf(","),sStr.length)+ ",wor="+(+total)+"; //**

catchup
04-24-2003, 10:52 AM
I changed the variable name cause it conflicted with another script on the page, but i still get that unterminated error:

data = sStr.substring(sStr.indexOf(","),sStr.length)+ ",tot="+(+tot)+";



bump

Jona
04-24-2003, 10:55 AM
Oops, my mistake--I didn't see that part. The below should work fine... Just every time you see a quote think, "Open one, [sees another] close one, [sees another] open one..."

data = sStr.substring(sStr.indexOf(","),sStr.length)+",tot="+(+tot);

catchup
04-24-2003, 11:01 AM
Great .... syntax error at the final line :(


<script type="text/javascript">
function Process (){
var firstRG = document.f6.wor; //first radio button group array
var secRG = document.f6.wok; //second radio button group array
var val1 = 0,val2 = 0,tot = 0;
//get value from first group
for(var n=0;n<firstRG.length;n++){
if(firstRG[n].checked){
val1 = parseInt(firstRG[n].value);
break;
}
}

for(var x=0;x<secRG.length;x++){
if(secRG[x].checked){
val2 = parseInt(secRG[x].value);
break;
}
}
tot = val1+val2;

}

var sStr = document.location.search;
var val = parseInt(sStr.substring(sStr.indexOf("=")+1,sStr.indexOf(",")));
var sum = (+tot)+((!isNaN(val))?val:0);
data = sStr.substring(sStr.indexOf(","),sStr.length)+",tot="+(+tot);
document.f6.action="Language.htm?tot="+sum+data ;
//return true;
}



Jona, sometimes "Programming < fun!"