PDA

View Full Version : Safari & Firefox problem



maximo
06-22-2007, 12:57 AM
I'm having problems getting this code to work in safari and firefox any idea's

function gotoPrint()
{
var printNum = Print.value
if(printNum=="1")
{
location.href="purcbody6x6P.html"
}

if(printNum =="2")
{
location.href="purcbody.html"
}

if(printNum =="3")
{
location.href="purcbody.html"
}

if(printNum =="4")
{
location.href="purcbody.html"
}

if(printNum =="5")
{
location.href="purcbody.html"
}

if(printNum =="6")
{
location.href="purcbody.html"
}

if(printNum =="0")
{
alert("Please select a print size")
return
}

}

Twey
06-22-2007, 01:22 AM
Where is Print defined in that code?

You can do that more neatly, too:
function gotoPrint() {
var printNum = /* whatever */;
printNum = parseInt(printNum, 10);
if(!printNum)
alert("Please select a print size.");
else if(printNum === 1)
location.href = "purcbody6x6P.html";
else if(printNum < 7)
location.href = "purcbody.html";
}

maximo
06-22-2007, 11:33 PM
the print is the name of the select tag I'm using this function on. so I would insert print.value where you have whatever?

Twey
06-23-2007, 01:13 AM
But it's not defined as a Javascript variable. You'd need to get a reference:
var printNum = document.getElementsByName("print")[0].value;

maximo
06-23-2007, 02:09 AM
Ok, I tried this but it still doesn't work in firefox or safari only IE

maximo
06-23-2007, 02:12 AM
I am using the onchange in the select tag instead of using a button, does firefox and safari not support that?

Twey
06-23-2007, 03:43 PM
Oh, my error, you have a capital P:
var printNum = document.getElementsByName("Print")[0].value;If it still doesn't work, it would be helpful to see your page.

maximo
06-23-2007, 08:54 PM
That was it. I'm sittin here starin at it and did'nt even notice it. Thanks alot I appreciate it