View Full Version : [Netscape] Get values from selectbox
320rwekfpl
09-23-2002, 01:24 PM
This code works fine in IE, but I just cannot find a way to make it work in Netscape. Does anyone know why?
function sendInfo2(formVar,box)
{
formVar.length = 0;
var strValue = new String();
for(var i=0; i<box.length; i++)
{
strValue += box[i].value;
if (i < box.length-1)
{
strValue += "<br>";
}
}
formVar.value = strValue;
}
beetle
09-23-2002, 04:10 PM
Can you show me what parameters are being passed to formVar and box?
320rwekfpl
09-24-2002, 09:29 AM
i'm trying to send a selectbox into a hidden field and these are the parameters that i send to the script;
sendInfo2(document.shop.data3,window.frames["cart"].document.c1.s3)
glenngv
09-24-2002, 10:32 AM
function sendInfo2(formVar,box)
{
var strValue = "";
for(var i=0; i<box.options.length; i++)
{
strValue += box.options[i].value;
if (i < box.options.length-1)
{
strValue += "<br>";
}
}
formVar.value = strValue;
}
320rwekfpl
09-27-2002, 09:10 AM
Doesn't work. Is there another way to get all values of a selectbox? (it even stopped working in IE...)?
glenngv
09-27-2002, 10:14 AM
it depends on how and when you call that function. are the parameters correct?
sendInfo2(document.shop.data3,window.frames["cart"].document.c1.s3)
if you want to test if the parameters are objects
put these alerts at the start of the function:
alert(formVar)
alert(box)
it should display [object]
320rwekfpl
09-27-2002, 10:30 AM
yes. i call it in body onload. it's confusing... i might as well post the whole page;
the js-file register.js
function sendInfo(formVar,box)
{
var strValue = "";
for(var i=0; i<box.options.length; i++)
{
strValue += box[i].options.value;
if (i < box.options.length-1)
{
strValue += "<br>";
}
}
formVar.value = strValue;
}
function sendInfo1(formVar,box)
{
var strValue = "";
for(var i=0; i<box.options.length; i++)
{
strValue += box[i].options.value;
if (i < box.options.length-1)
{
strValue += "<br>";
}
}
formVar.value = strValue;
}
function sendInfo2(formVar,box)
{
var strValue = "";
for(var i=0; i<box.options.length; i++)
{
strValue += box[i].options.value;
if (i < box.options.length-1)
{
strValue += "<br>";
}
}
formVar.value = strValue;
}
function sendInfoAntal(formVar,box)
{
var strValue = "";
for(var i=0; i<box.options.length; i++)
{
strValue += box[i].options.value;
if (i < box.options.length-1)
{
strValue += "<br>";
}
}
formVar.value = strValue;
}
function sendInfoSum()
{
document.shop.data4.value = parent.frames["cart"].document.c1.fSumma.value;
}
function sendInfo5(box)
{
var strValue = "";
for(var i=0; i<box.options.length; i++)
{
strValue += box[i].options.value;
if (i < box.options.length-1)
{
strValue += "<br>";
}
}
document.writeln(strValue);
}
function sendInfo3(box)
{
var strValue = "";
for(var i=0; i<box.options.length; i++)
{
strValue += box[i].options.value;
if (i < box.options.length-1)
{
strValue += "<br>";
}
}
document.writeln(strValue);
}
function sendInfo4(box)
{
var strValue = "";
for(var i=0; i<box.options.length; i++)
{
strValue += box[i].options.value;
if (i < box.options.length-1)
{
strValue += "<br>";
}
}
document.writeln(strValue);
}
function sendInfo6(box)
{
var strValue = "";
for(var i=0; i<box.options.length; i++)
{
strValue += box[i].options.value;
if (i < box.options.length-1)
{
strValue += "<br>";
}
}
document.writeln(strValue);
}
function sendInfoSum2()
{
document.writeln(parent.frames["cart"].document.c1.fSumma.value);
}
function validate()
{
if (document.shop.data5.value=="")
{
describe("Fyll i ditt namn.");
return false;
}
else if (document.shop.data8.value=="")
{
describe("Vart skall ordern levereras?");
return false;
}
else if (document.shop.data7.value.indexOf("@") == -1)
{
describe("Fyll i en korrekt E-post adress.");
return false;
}
else
{
parent.cart.location = "tom.htm";
parent.menu.location = "menu.htm";
return true;
}
}
function utskriftskopia()
{
switch(navigator.platform)
{
case "MacPPC" :
openWindow();
break;
case "Mac68K" :
openWindow();
break;
case "Win32" :
parent.frames["articles"].print();
break;
case "Win16" :
parent.frames["articles"].print();
break;
default :
parent.frames["articles"].print();
break;
}
}
function openWindow()
{
var notUse = 'directories=no, menubar=no, titlebar=no, toolbar=yes';
notUse += 'locationbar=no, statusbar=no';
var toolOpt = 'scrollbars=yes, width=410, height=200, resizable=no';
var totalOpt = notUse + ',' + toolOpt;
var newWin = open('', 'kvitto', totalOpt);
newWin.document.writeln("<head><title>Kvitto</title></head>");
newWin.document.writeln("<body bgcolor=#ffffff>");
newWin.document.writeln("<table border=1 cellspacing=0 cellpadding=2 bgcolor=#ffffcc><tr>");
newWin.document.writeln("<td><font face=verdana size=1><b>Artikelnr: </b><br>"+document.shop.data1.value+"</td></font>");
newWin.document.writeln("<td><font face=verdana size=1><b>Namn: </b><br>"+document.shop.data2.value+"</td></font>");
newWin.document.writeln("<td><font face=verdana size=1><b>Pris/st (SEK): </b><br>"+document.shop.data3.value+"</td></font>");
newWin.document.writeln("<td><font face=verdana size=1><b>Antal: </b><br>"+document.shop.data9.value+"</td></font>");
newWin.document.writeln("</tr><tr>");
newWin.document.writeln("<td colspan=4 align=right><font face=verdana size=1><b>Summa: </b>"+document.shop.data4.value+"</td></font>");
newWin.document.writeln("</tr><tr>");
newWin.document.writeln("<td colspan=4><font face=verdana size=1><b>Levereras till;</b></td></font>");
newWin.document.writeln("</tr><tr>");
newWin.document.writeln("<td colspan=4><font face=verdana size=1><b>Namn: </b>"+document.shop.data5.value+"</td></font>");
newWin.document.writeln("</tr><tr>");
newWin.document.writeln("<td colspan=4><font face=verdana size=1><b>Telefon: </b>"+document.shop.data6.value+"</td></font>");
newWin.document.writeln("</tr><tr>");
newWin.document.writeln("<td colspan=4><font face=verdana size=1><b>Adress: </b>"+document.shop.data7.value+"</td></font>");
newWin.document.writeln("</tr><tr>");
newWin.document.writeln("<td colspan=4><font face=verdana size=1><b>E-post: </b>"+document.shop.data8.value+"</td></font>");
newWin.document.writeln("</tr><tr></table>");
newWin.document.writeln("</body>");
newWin.document.close();
newWin.focus();
}
and the complete page;
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=ISO-8859-1">
<meta name="generator" content="Adobe GoLive 5">
<title>betala</title>
<script language='javascript' src="js/register.js">
</script>
<link href="css/webstyle.css" rel="stylesheet" media="screen">
</head>
<body onLoad='sendInfo1(document.shop.data1,window.frames["cart"].document.c1.s1);sendInfo2(document.shop.data2,window.frames["cart"].document.c1.s2);sendInfo(document.shop.data3,window.frames["cart"].document.c1.s3);sendInfoSum();sendInfoAntal(document.shop.data9,window.frames["cart"].document.c1.s4)'>
<script language="JavaScript" src="js/description.js">
</script>
<form action="http://195.17.102.215/4DAction/PostMetaContact/999999/ShopOrder" method="post" name="shop" onSubmit='return validate()'>
<input type="hidden" name="data1"><input type="hidden" name="data2"><input type="hidden" name="data3"><input type="hidden" name="data4"><input type="hidden" name="data9">
<table border="0" cellpadding="0" cellspacing="0" width="400">
<tr>
<td class="menutop" width="82"><b>Artikelnummer</b></td>
<td class="menutop" align="right" width="200"><b>Namn</b></td>
<td class="menutop" align="right" width="75"><b>Pris/st (SEK)</b></td>
<td class="menutop" colspan="3" align="right" width="50"><b>Antal</b></td>
</tr>
<tr>
<td class="menutop" width="82"><script>sendInfo3(window.frames["cart"].document.c1.s1);</script></td>
<td class="menutop" align="right" width="200"><script>sendInfo4(window.frames["cart"].document.c1.s2);</script></td>
<td class="menutop" align="right" width="75">
<script>sendInfo6(window.frames["cart"].document.c1.s3);</script>
</td>
<td class="menutop" colspan="3" align="right" width="50">
<script>sendInfo5(window.frames["cart"].document.c1.s4);</script>
</td>
</tr>
<tr>
<td colspan="2" align='right' width="282"></td>
<td align="right" valign="bottom" width="75"><b>Summa:</b></td>
<td class="menumiddle" colspan="3" align="right">
<script>sendInfoSum2();</script>
</td>
</tr>
<tr>
<td valign="bottom" align="left" width="82">Namn*</td>
<td align="right" colspan="5"><input type="text" name="data5" size="50" value="" onfocus="describe('')"></td>
</tr>
<tr>
<td align="left" valign="bottom" width="82">Telefon</td>
<td colspan="5" align="right"><input type="text" name="data6" size="50" onfocus="describe('')"></td>
</tr>
<tr>
<td align="left" valign="bottom" width="82">Adress*</td>
<td align="right" colspan="5"><input type="text" name="data8" size="50" onfocus="describe('')"></td>
</tr>
<tr>
<td align="left" valign="bottom" width="82">Epost*</td>
<td align="right" colspan="5"><input type="text" name="data7" size="50" onfocus="describe('')"></td>
</tr>
<tr>
<td align="right" colspan="6"><input type="submit" name="submit" value="Beställ" class='input' onmouseover="describe('')"></td>
</tr>
<tr>
<td align="right" colspan="6"><input type="button" name="kutskrift" value="Fönster för utskrift" class='input' onClick='utskriftskopia()' onmouseover="describe('Klicka här för att skriva ut alt. visa ett fönster för utskrift.')"></td>
</tr>
</table>
</form>
<span id="desc" style="position: absolute"></span>
</body>
</html>
glenngv
09-27-2002, 11:01 AM
why do you have so many similar functions.
the function sendInfo() is already generic with the elements objects as parameters. you can call it many times each time passing different arguments.
did you put:
alert(box)
what does it say?
320rwekfpl
09-27-2002, 12:43 PM
I was having problems with the generic method. Maybe I should take a look at it now. Anyway, I found out that the script didn't malfunction... The problem was that I had called the selects with window instead of parent. Anyway, thanks for the help!
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.