Forum Moderators: open

Message Too Old, No Replies

Programmatically clicking on a link to display details onclick=javascr

         

promax

6:57 pm on Dec 22, 2009 (gmt 0)

10+ Year Member



Hi
I need to programmatically click on a link );"ver mais" in the following code where I can see the details.

I tried so many things without any luck like
odoc.getElementById('divVerMais_319').onclick='javascript:toggleDetails(319)'

id=ctl00_ContentPlaceHolder1_dlResultados_ctl05_InterDataList><SPAN><STRONG>Insolvente/Devedor:</STRONG> ABC Ltd <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<STRONG>Nif: </STRONG>504000000 </SPAN></SPAN><BR><SPAN style="DISPLAY: none" id=Details_319 runat="server"></SPAN>
<DIV style="TEXT-ALIGN: right" id=divVerMais_319 class=vermais runat="server"><A title="Ver detalhes do processo 574, " onclick=javascript:toggleDetails(319); href="javascript:void(0);">ver mais</A> </DIV></DIV></SPAN></SPAN><BR>

Can anyone help me?
Thanks a lot
Sam

rocknbil

8:43 pm on Dec 22, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome aboard promax. Never use href="javascript "anything" or "void." These are not urls. Put a real URL in there to content in case JS is disabled.

What you want to do in your onclick is return false. this will stop the "real link" from navigating the page.

Second, although click events on divs, paragraphs, etc. WILL work, it's a better idea to put the event directly on the link. You can style a link to "fill out" the div.

On another note, spans are inline elements, divs are block. You can't put divs inside spans, but you can put spans inside divs.

Working example:


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Untitled</title>
<style type="text/css">
#div1 { width: 400px; margin:auto; TEXT-ALIGN: right; border: 1px solid #000000; }
#divVerMais_319 { width: 370px; height: 70px; display:block; padding: 50px 30px 30px 0; }
</style>
<script type="text/javascript">
window.onload=function() {
if (document.getElementById('divVerMais_319')) {
document.getElementById('divVerMais_319').onclick= function() { return toggleDetails(319) };
}
};
function toggleDetails (some_id) {
alert('You have sent ' + some_id + ' to this function.');
return false;
}
</script>
</head>
<body>
<div id="div1"><a href="alternate-content.html"
title="Ver detalhes do processo 574," id="divVerMais_319">ver mais</a> </div>
</body>
</html>

promax

1:20 am on Dec 23, 2009 (gmt 0)

10+ Year Member



Hi rocknbil
Thank for the reply, i should have been more clear. I'm not writing this code. I'm writing a data capture program to extract some public info from a site automatically, where after a query it will display set of information. Then i need to progrmatically click the link to open a snippet that contains more details.
In my program i create ie object, do the query and it display the summary as above, so i need to work out how to click the ver mais link automatically to open the details snippet.

Could you help
Thanks and Regards
Sam

Fotiman

2:18 am on Dec 23, 2009 (gmt 0)

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



You might want to check out the Yahoo UI Library. It can Simulate Events [developer.yahoo.com].