onclick event not working in Netscape 6

M

moondaddy

I have a <a> element in a datagrid which wraps some asp.net labels. this
element also has an onclick event which does not fire in netscape 6 (and
perhaps other browsers for all I know...). Below is the code for this. the
onclick event calls a javascript function which I put an alert in the firt
line to tell me if its working. It does work in IE. Any ideas on how to
get netcrap... oops, I'm sorry, netscape to fire the onclick event?


<a onclick='CartAdd(<%# DataBinder.Eval(Container.DataItem, "SKU1")%>)' >
<asp:Label id="lblItem1" runat="server" CssClass="clsGdChmNameStnd">
<%# DataBinder.Eval(Container.DataItem, "Item1")%>
</asp:Label><br>
<asp:Label id="lblSKU1" runat="server" CssClass="clsGdChmSKUStnd">sku: <%#
DataBinder.Eval(Container.DataItem, "SKU1")%> </asp:Label>
<br>
<asp:Label id="lblPrice1" runat="server" CssClass="clsGdChmSKUStnd">
<%# DataBinder.Eval(Container.DataItem, "Price1") %>
</asp:Label>
</a>
 
B

bruce barker

turn on the javascript console in netscape to find out the scripting error,
or post the rendered html, so we can see the actual generated and called
script. whats the CartAdd script look like?

-- bruce (sqlwork.com)
 
M

moondaddy

OK sorry about that.

Here's the html it generated:

<a onclick='CartAdd(1588)' style="CURSOR: hand">
<span id="_ctl3_dgItems__ctl2_lblItem1"
class="clsGdChmNameStnd">Daisys</span><br>
<span id="_ctl3_dgItems__ctl2_lblSKU1" class="clsGdChmSKUStnd">sku:
1588</span>
<br>
<span id="_ctl3_dgItems__ctl2_lblPrice1"
class="clsGdChmSKUStnd">$18.00</span>
</a>


And here's the jscript function it calls:

<script language=jscript type=text/Jscript>
function CartAdd(value)
{
alert('hdSKU' );
_ctl3_hdSKU =value;
document.all('_ctl3_hdSKU').value =value;
document.all('_ctl3_btnPostBack').click();
}
</script>






--
(e-mail address removed)
bruce barker said:
turn on the javascript console in netscape to find out the scripting error,
or post the rendered html, so we can see the actual generated and called
script. whats the CartAdd script look like?

-- bruce (sqlwork.com)
 
M

moondaddy

OK I fixed part of the problem, but I still need help. The part I fixed was
changing jscript to javascript in this line:
script language=jscript type=text/Jscript>

So now the onclick event fires and the alert in the function 'CartAdd' being
called runs, but at least part of the code doenst run after that. Whats
supposed to happen is the onclick event passes a SKU number as a parameter
into the function CartAdd. Then CartAdd put this value into a hidden
control and fires an OnClick event for a button to cause a postback. I'm
pretty sure there's no postback happening, but I'm not sure exactly where
the problem is. Here's the CartAdd function again, and the html for the
hidden element and the button for doing the postback. NOTE: all of this
works OK in IE 5+


<script language=javascript type=text/JavaScript>
function CartAdd(value)
{
alert('hdSKU' );
_ctl3_hdSKU =value;
document.all('_ctl3_hdSKU').value =value;
document.all('_ctl3_btnPostBack').click();
}
</script>


<input name="_ctl3:hdSKU" id="_ctl3_hdSKU" type="hidden" value="1588" /><br>
<input language="javascript" onclick="__doPostBack('_ctl3$btnPostBack','')"
name="_ctl3:btnPostBack" id="_ctl3_btnPostBack" type="button"
style="DISPLAY: none" value="PostBack" />

--
(e-mail address removed)
moondaddy said:
OK sorry about that.

Here's the html it generated:

<a onclick='CartAdd(1588)' style="CURSOR: hand">
<span id="_ctl3_dgItems__ctl2_lblItem1"
class="clsGdChmNameStnd">Daisys</span><br>
<span id="_ctl3_dgItems__ctl2_lblSKU1" class="clsGdChmSKUStnd">sku:
1588</span>
<br>
<span id="_ctl3_dgItems__ctl2_lblPrice1"
class="clsGdChmSKUStnd">$18.00</span>
</a>


And here's the jscript function it calls:

<script language=jscript type=text/Jscript>
function CartAdd(value)
{
alert('hdSKU' );
_ctl3_hdSKU =value;
document.all('_ctl3_hdSKU').value =value;
document.all('_ctl3_btnPostBack').click();
}
</script>
 
B

Bruno Sirianni

I'm not sure that this is the problem ... but you can try to replace with
this :
document.all['_ctl3_hdSKU'].value =value;
document.all['_ctl3_btnPostBack'].click();

this code is used for?
_ctl3_hdSKU =value;


Brun
 
J

J'son

Bruno,

document.all is only supported in IE. Netscape uses document.layers.
Heres a simple browser detection script:

The most common pattern in JavaScript scripts is probably the section
that determines the browser type. And its structure is probably
something like:

<SCRIPT LANGUAGE="JavaScript">
<!--
if (document.all) {
document.write("Internet Explorer Detected");
}
else if (document.layers) {
document.write("Netscape Navigator Detected");
}
else {
document.write("Unrecognized Browser Detected");
}
// -->
</SCRIPT>

Full link to code excerpt above:
http://webreference.com/js/tips/001125.html

If you store the browser variable in a global variable, you can use it
in an if statement in your function to ensure your modifying the right
values:

isIE = (document.all);

if (isIE)
{
document.all('_ctl3_hdSKU').value =value;
document.all('_ctl3_btnPostBack').click();
}
else
{
//do something else here.. not sure how to get to your field and
button in Netscape (document.layers leads nowhere I believe) - maybe
document.forms[form index].elements[field/button index]? - that is
cross browser compliant.
}

My 2 cents...

J'son

Bruno Sirianni said:
I'm not sure that this is the problem ... but you can try to replace with
this :
document.all['_ctl3_hdSKU'].value =value;
document.all['_ctl3_btnPostBack'].click();

this code is used for?
_ctl3_hdSKU =value;


Brun

moondaddy said:
OK I fixed part of the problem, but I still need help. The part I fixed was
changing jscript to javascript in this line:
script language=jscript type=text/Jscript>

So now the onclick event fires and the alert in the function 'CartAdd' being
called runs, but at least part of the code doenst run after that. Whats
supposed to happen is the onclick event passes a SKU number as a parameter
into the function CartAdd. Then CartAdd put this value into a hidden
control and fires an OnClick event for a button to cause a postback. I'm
pretty sure there's no postback happening, but I'm not sure exactly where
the problem is. Here's the CartAdd function again, and the html for the
hidden element and the button for doing the postback. NOTE: all of this
works OK in IE 5+


<script language=javascript type=text/JavaScript>
function CartAdd(value)
{
alert('hdSKU' );
_ctl3_hdSKU =value;
document.all('_ctl3_hdSKU').value =value;
document.all('_ctl3_btnPostBack').click();
}
</script>


<input name="_ctl3:hdSKU" id="_ctl3_hdSKU" type="hidden" value="1588"
/> said:
<input language="javascript" onclick="__doPostBack('_ctl3$btnPostBack','')"
name="_ctl3:btnPostBack" id="_ctl3_btnPostBack" type="button"
style="DISPLAY: none" value="PostBack" />

--
(e-mail address removed)
this.
the the
firt how
to CssClass="clsGdChmSKUStnd">sku:
<%#
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top