Forum Moderators: open

Message Too Old, No Replies

Why this won't work in IE 6

         

tjodalv

12:10 pm on Sep 19, 2006 (gmt 0)

10+ Year Member



Hello

I have JS function that works in almost all browsers (IE 7, Opera 9,FF 1.5) but it doesn't work in IE 6. Could someone help me to adjust function. Here's the function:


function ProvjeriPolje(min_qty,pid) {
if (parseInt(document.getElementById('qty'+pid).value) == "0" ¦¦ parseInt(document.getElementById('qty'+pid).value) < min_qty ¦¦ document.getElementById('qty'+pid).value.length < "1")
{
alert("Error")
return false;
}
else if (document.getElementById('dimenzije'+pid).value == "#*$!")
{
alert("Dimension is not selected");
return false;
}
else {
url = "AddCart.asp?a=dodaj_u_kosaru&pid=" + pid
document.dodaj.action = url;
document.dodaj.submit();
}
}

penders

1:42 pm on Sep 19, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Do you get an error? In what way is it not working?

You seem to have a semicolon missing here....

url = "AddCart.asp?a=dodaj_u_kosaru&pid=" + pid; // Missing SEMICOLON!

You could try replacing these two lines (at the end) with...

document.getDocumentById('dodaj').setAttribute('action',url); 
document.getDocumentById('dodaj').submit();

And I don't think you need the ".." (quotes) around the integers...

if (parseInt(document.getElementById('qty'+pid).value) == 0 ¦¦ parseInt(document.getElementById('qty'+pid).value) < min_qty ¦¦ document.getElementById('qty'+pid).value.length < 1)

...since I think you are comparing integers with integers. Adding quotes will only cause JS to do further type conversion.

Not sure why it would work in others and not IE6 though.

kaled

3:43 pm on Sep 19, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Certainly you should remove the quotes around the 1 and the 0. Also, you might add return true after the form submission.

BEST PRACTICE
'{' should follow on same line after if
Local variables should be declared with var.
Repeated code can usually be improved.

if (parseInt(document.getElementById('qty'+pid).value) == "0" ¦¦ parseInt(document.getElementById('qty'+pid).value) < min_qty ¦¦ document.getElementById('qty'+pid).value.length < "1")
{

should read
var v = document.getElementById('qty'+pid).value;
if (parseInt(v) == 0 ¦¦ parseInt(v) < min_qty ¦¦ v.length < 1) {

Kaled

tjodalv

9:40 pm on Sep 19, 2006 (gmt 0)

10+ Year Member



I've tried this:

document.getDocumentById('dodaj').setAttribute('action',url);
document.getDocumentById('dodaj').submit();

But it doesn't work. My form name is dodaj. I've putted semicolon but still not working.

kaled

1:05 am on Sep 20, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Precisely, how are you calling this function?

Kaled.

tjodalv

7:58 am on Sep 20, 2006 (gmt 0)

10+ Year Member



I list products from database, and in that loop I have:


<a href="javascript:void(0)" onClick="ProvjeriPolje('<% =rsProducts("min_qty") %>','<% =rsProducts("id") %>');">

I must say that all that works in every browser except IE 6.0.

kaled

9:04 am on Sep 20, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What happens if you use href="#"

You need to enable error reporting in IE.

Kaled.

penders

9:21 am on Sep 20, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



<a href="javascript:void(0)" onClick="ProvjeriPolje('<% =rsProducts("min_qty") %>','<% =rsProducts("id") %>'); return false;">

Do you need a 'return false;', as indicated, to prevent the browser from trying to follow the href link?

tjodalv

10:49 am on Sep 20, 2006 (gmt 0)

10+ Year Member



Thank you penders return false; in link helped. Thank you very much.