Link to home
Start Free TrialLog in
Avatar of Irmawaty
Irmawaty

asked on

executing javascript using webbrowser control

Hello experts,

I am wondering if anyone knows how to call and execute a javascript function from webbrowser control.

so far I have:

HTMLDocument myDoc = new HTMLDocumentClass();
myDoc = (HTMLDocument) axWebBrowser1.Document;
Avatar of Jeff Certain
Jeff Certain
Flag of United States of America image

Put the javascript in your page. Load your page in the browser. :)
Avatar of Irmawaty
Irmawaty

ASKER

Chaosian,

Sorry I didn't explain my question very well. What i am intending to do here is doing web automation. There is a link look like this: <a href="javascript:chooseGroups('sss','sss')">Choose item</a>.
For some reasons, using the following codes:
HTMLDocument myDoc = new HTMLDocumentClass()
IHTMLElementCollection eventLinks = myDoc.links

I only get a list of links that is outside of <form> tag. So I try to work around this by calling the javascript instead.

Here is what I have now:

object loc = "https://www.aaa.com/";
object null_obj_str = "";
System.Object null_obj = 0;
this.axWebBrowser1.Navigate2(ref loc , ref null_obj, ref null_obj, ref null_obj_str, ref null_obj_str);

HTMLDocument myDoc = new HTMLDocumentClass();
myDoc = (HTMLDocument) axWebBrowser1.Document;
ASKER CERTIFIED SOLUTION
Avatar of wtconway
wtconway

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry,
still to no avail...
hmmm...that code worked fine for me and I used experts-exchange live html over the net. Could you possibly post your entire code that involves this?

More questions: Is you <a> tag controlled by you? Could you post the entire html file? And will it ever change?
Also:

Are you getting an error you just not getting anything clicked?
Hey I think I know what it is: If you're running XP SP 2 and try to click a link that is formatting like so:

<a href="javascript:alert('hello');">Hello</a>

IE will ask for permission before executing the code....the web control in .NET may not allow this interacting and therefore just not execute the click. If you can control the format of the link, try doing something like this instead:

<a href="#" onclick="javascript:chooseGroups('sss','sss')">Choose item</a>.

And see if that works.
nevermind...I just tried it and it worked fine. Just answer the previous comments before my last one.
There is no <a> tag with the href that I want to click. Thus, it never enters the if statement.

I don't control <a>, I just retrieve the HTML code
Here is the editted version of the HTML code: (the link that I am talking about is in <FORM> called "Item group")

<HTML>
<HEAD><TITLE></TITLE>
</HEAD>
<BODY LEFTMARGIN="0" TOPMARGIN="0" MARGINWIDTH="0" MARGINHEIGHT="0">
<script language="Javascript" src="/include/dropmenu.js"></script>
<!-- BEGIN HEADER HTML -->

--CONTAINS THE LINKS THAT SHOWS UP IN IHTMLElementCollection

<!-- END HEADER HTML -->

<!--API Render Time End New Header: 78ms -->
<!--API Render Time: 94ms -->
<table height="100%" width="100%" cellpadding=0 cellspacing=0 border=0>
      <tr>
            <td valign="top"  width="150" NOWRAP >
                  --CONTAINS LINKS THAT DO NOT SHOW IN IHTMLElementCollection
            </td>
      </tr>
      
<form name="eventmaintenance" action="/xxx/eventcalendar/event_maintenance.asp?ch=H3&div=1&appType=xxx" method="POST">

<form name="eventmaintenance" action="/xxx/xxx/event_maintenance.asp?ch=H3&div=1&appType=xxx" method="POST">
<table width="100%" bgcolor='#ffffff' border="0">
<input type=Hidden name='Action'>
<input type=Hidden name='EventId' value="-1">
<input type=Hidden name='ParentId' value="">
<input type=Hidden name='CopyFromEventId' value="">
<input type=Hidden name='OldEventId' value="-1">
<input type=Hidden name='Level' value="">

<tr><td align="CENTER" valign="MIDDLE" class="subDark" bgcolor="#3366FF">Describe Event</td></tr>
<tr>
<td>
<table width="100%" border="0">
<tr>
<td class="sub">Name:</td>
<td><input type="Text" name="EventName" value="" maxlength="40" size="20"></td>
<td class="sub">Description</td>
<td ><input type="Text" name="EventDesc" value="" maxlength="255" size="45"><br><font size=-3>(max of 255 characters)</font></td>
</tr>
</tr>
<tr>
<td class="sub">Event Category:</td>
<td>
<select name="EventCategory" onchange="refreshFromFormData()">
<option value="">--Choose--</option>
<option value="9">option1    </option>
<option value="13">option2  </option>
<option value="18">option3  </option>
<option value="27">option4 </option>

</select>
</td>
<td class="sub">Event<br>Type Code:</td>
<td>
<select name="EventTypeCode">
<option value="">--Choose--</option>
</select></td>
</tr>

</table>
</td></tr>
<tr><td align="CENTER" valign="MIDDLE" class="subDark" bgcolor="#3366FF">Time Occurrence</td></tr>
<tr><td>
<table width="100%" border="0">
<tr>
<td class="sub">Event Occurance:</td>
<td class="sub"><input type="radio" checked onClick="form.submit()" name="OccuranceType" value="-1">Once<input type="radio"  onClick="form.submit()" name="OccuranceType" value="0">Annually</td>
<td></td><td></td></tr>
</table>
<table id="oncerows" width="100%" border="0">

<tr>
<td></td>
<td class="sub">Event<br>Begin Date:</td>
<td>
<SELECT name="BeginDateYYYY" onchange="changeSelectionDays('eventmaintenance','Begin')"></SELECT>
<SELECT name="BeginDateMM" onchange="changeSelectionDays('eventmaintenance','Begin')"></SELECT>
<SELECT name="BeginDateDD" onchange="changeSelectionDays('eventmaintenance','Begin')"></SELECT></td>
<td></td></tr>
<tr>
<td class="sub"></td><td class="sub">Event<br>End Date:</td>
<td>
<SELECT name="EndDateYYYY" onchange="changeSelectionDays('eventmaintenance','End')"></SELECT>
<SELECT name="EndDateMM" onchange="changeSelectionDays('eventmaintenance','End')"></SELECT>
<SELECT name="EndDateDD" onchange="changeSelectionDays('eventmaintenance','End')"></SELECT></table>
</td></tr>

<tr>
<td nowrap class="normal"><input size="9" name="mdseId" value="" type="text"><input name="mdseDesc" size="30" type="text" value="">&nbsp;<a class=bold href="javascript:chooseGroups('item','-1')">Item group</a>
<td></td>
</tr>

</table>
</form>
</td></tr></table></td></tr></table>
</body></html>

<SCRIPT LANGUAGE="JavaScript">
var bDecided = false;
var bSeries = true;
var bOccChange = false;
var bChild = eval("false");
var ParentID = "";
var parent_EventName = "";
var parent_EventStatus = "";
var parent_EventDesc = "";
var parent_EventTypeCode = "";
var parent_OwnerTypeCode = "";

var g_action;
var myTimeOut;


function refreshFromFormData() {
      document.eventmaintenance.Action.value = "PULLFROMFORM";
      document.eventmaintenance.submit();
}


function open_popupCOE(value,EventId,ch,div,APPTYPE,mdse_level_id,bu_group_id,mdseLevel)
{
      var url = "/xxx/xxx/event_createCOE.asp?ch="+ch+"&div="+div+"&appType="+APPTYPE+"&caller=event_maintenance.asp&EventId=" +EventId+ "&mdseId=" + mdse_level_id+ "&bu_group_id=" + bu_group_id + "&mdseLevel=" + mdseLevel+"&Type="+value+" ";
      window.location = url;

}

function clearForm() {
      document.eventmaintenance.EventId.value = "-1";
      document.eventmaintenance.Action.value = "CLEAR";
      document.eventmaintenance.submit();
}


function bCreateNewEvent()
{
      return (parent_EventStatus == "2" && document.eventmaintenance.EventStatus.options[document.eventmaintenance.EventStatus.selectedIndex].value != parent_EventStatus);
}


function areYouSure()
{
      if(bCreateNewEvent())
            if(confirm("By continuing, this action will create a new one time event. Are you sure you want to continue?"))
                  decided(false);
            else
                  clearTimeOut();
      else
            decided(false);
}


function decided(bChoice)
{
      bSeries = bChoice;
      bDecided = true;
}



function checkStatus()
{
      if(!bDecided){
            myTimeOut = setTimeout("checkStatus()", 500);
      }
      else{
            if(!document.layers)
                  hide_modifyOccurrenceOrSeriesPopup("modOcc");

            clearTimeOut();
            if(validateForm()){
                  if(bSeries){
                        g_action = "MODIFYSERIESOCCURRENCE";
                        if(bOccChange)
                              alert("Occurrence information can only be changed from the event that begins the series. All other changes will be applied to the series.");
                  }
                  else{
                        if(bCreateNewEvent()){
                              if(!bOccChange)
                              {
                                    //lsirvin added this line to put the current EventId value into the OldEventId value.
                                    document.eventmaintenance.OldEventId.value = document.eventmaintenance.EventId.value;
                                    document.eventmaintenance.EventId.value = "-1";
                              }
                              g_action = "CREATEFROMOCCURRENCE";
                        }
                  }

                  document.eventmaintenance.Action.value = g_action;
                  document.eventmaintenance.submit();
            }
      }
}


function clearTimeOut()
{
      clearTimeout(myTimeOut);
}


function submitForm(action) {
      var bGood = false;
      LEVEL = "";

      switch(action){
            case "CREATE":
                  bGood = (validateForm()) ? validateImpact() : false;
                  break;
            case "MODIFYSERIES":
                  bGood = validateForm();
                  break;
            case "ADDIMPACT":
                  bGood = validateImpact();
                  if (document.eventmaintenance.ImpactValue.value=="")
                        action = "ADDLEVEL";
                        document.eventmaintenance.action +=  "\#level";
                  break;
            case "ADDIMPACTSERIES":
                  bGood = validateImpact();
                  if (document.eventmaintenance.ImpactValue.value=="")
                        action = "ADDLEVELSERIES";
                        document.eventmaintenance.action +=  "\#level";
                  break;
            default:
                  bGood = true;
                  break;
      }

      if (bGood) {
            document.eventmaintenance.Level.value=LEVEL;
            document.eventmaintenance.Action.value=action;
            document.eventmaintenance.submit();
      }
}



      if(document.eventmaintenance.mdseId.value==""&&document.eventmaintenance.mdseLevel[document.eventmaintenance.mdseLevel.selectedIndex].value != 0) {
            alert("The identifier field cannot be empty.");
            bGood = false;
      }
      if(!isRealNumber(document.eventmaintenance.buId.value)) {
            alert("xxxx");
            bGood = false;
      }
      return bGood;
}


function validateForm() {
      var bGood = true;
      //Check Describe Event
      if (document.eventmaintenance.EventTypeCode.options[document.eventmaintenance.EventTypeCode.selectedIndex].value=="") { bGood=false; }
      if (RTrim(document.eventmaintenance.EventDesc.value)=="") { bGood=false; }
      if (RTrim(document.eventmaintenance.EventName.value)=="") { bGood=false; }
      if (!bGood) { alert("Fill in all Event Description fields."); }

      //Check Time Occurance
      if (document.eventmaintenance.OccuranceType[0].checked) { //Once
            var begin = new Date(document.eventmaintenance.BeginDateMM.options[document.eventmaintenance.BeginDateMM.selectedIndex].value + "/" + document.eventmaintenance.BeginDateDD.options[document.eventmaintenance.BeginDateDD.selectedIndex].value + "/" + document.eventmaintenance.BeginDateYYYY.options[document.eventmaintenance.BeginDateYYYY.selectedIndex].value);
            var end = new Date(document.eventmaintenance.EndDateMM.options[document.eventmaintenance.EndDateMM.selectedIndex].value + "/" + document.eventmaintenance.EndDateDD.options[document.eventmaintenance.EndDateDD.selectedIndex].value + "/" + document.eventmaintenance.EndDateYYYY.options[document.eventmaintenance.EndDateYYYY.selectedIndex].value);
            
            if (end < begin) {
                  alert("Event End Date must be after Event Begin Date.");
                  bGood = false;
            }

      } else if (document.eventmaintenance.OccuranceType[1].checked) { //Annual
            if (document.eventmaintenance.AnnuallyType[0].checked) { //Exact Day
                  if (document.eventmaintenance.SpecificDateMonth.options[document.eventmaintenance.SpecificDateMonth.selectedIndex].value=="-1" || document.eventmaintenance.SpecificDateDay.options[document.eventmaintenance.SpecificDateDay.selectedIndex].value=="-1") {
                        alert("Choose Exact Day Info.");
                        bGood=false;
                  }
            } else if (document.eventmaintenance.AnnuallyType[1].checked) { //Day of Week
                  if (document.eventmaintenance.DayWhichWeek.options[document.eventmaintenance.DayWhichWeek.selectedIndex].value=="-1" || document.eventmaintenance.DayWhichDay.options[document.eventmaintenance.DayWhichDay.selectedIndex].value=="-1" || document.eventmaintenance.DayWhichMonth.options[document.eventmaintenance.DayWhichMonth.selectedIndex].value=="-1") {
                        alert("Choose Day of Week Info.");
                        bGood=false;
                  }
            } else if (document.eventmaintenance.AnnuallyType[2].checked) { //Holiday
                  if (document.eventmaintenance.HolidayCode.options[document.eventmaintenance.HolidayCode.selectedIndex].value=="-1") {
                        alert("Choose Holiday Info.");
                        bGood=false;
                  }
            } else {
                  alert("Fill in Event Time Occurrance.");
                  bGood = false;
            }

            if (document.eventmaintenance.DaysBeforeEvent.value==""||document.eventmaintenance.DaysAfterEvent.value=="") {
                  alert("Fill in Before/After Days fields.");
                  bGood = false;
            }
            if (document.eventmaintenance.RemindDays.value=="") {
                  alert("Fill in Remind Days.");
                  bGood = false;
            }
            if (!document.eventmaintenance.EndCode[0].checked && !document.eventmaintenance.EndCode[1].checked) {
                  alert("Select when event ends.");
                  bGood = false;
            }
            if (document.eventmaintenance.EndCode[1].checked && document.eventmaintenance.OccurranceCount.value=="") {
                  alert("Choose in how many years the Event will end.");
                  bGood = false;
            }
            document.eventmaintenance.DaysBeforeEvent.value = document.eventmaintenance.DaysBeforeEvent.value.replace(",","");
            document.eventmaintenance.DaysAfterEvent.value = document.eventmaintenance.DaysAfterEvent.value.replace(",","");
            document.eventmaintenance.RemindDays.value = document.eventmaintenance.RemindDays.value.replace(",","");
            document.eventmaintenance.OccurranceCount.value = document.eventmaintenance.OccurranceCount.value.replace(",","");
            if (!isRealNumber(document.eventmaintenance.DaysBeforeEvent.value)||!isRealNumber(document.eventmaintenance.DaysAfterEvent.value)||!isRealNumber(document.eventmaintenance.RemindDays.value)||!isRealNumber(document.eventmaintenance.OccurranceCount.value)) {
                  alert("Time Occurrance Fields must be whole numbers.");
                  bGood = false;
            }
      }
      return bGood;
}


function clearLevelFields() {
      document.eventmaintenance.mdseId.value="";
      document.eventmaintenance.mdseDesc.value="";
      document.eventmaintenance.buId.value="";
      document.eventmaintenance.buDesc.value="";
      document.eventmaintenance.ImpactValue.value="";
}
function makeSelectedIndexZero(field) {
      eval("document.eventmaintenance." + field + ".selectedIndex=0;");
}

function chooseGroups(which,EventId) {
      if (EventId!="-1") {
            var url = "/xxx/xxx/" + which + "_group.asp?ch=H3&div=1&appType=xxx&EventId=-1&mdseLevel=" + document.eventmaintenance.mdseLevel.value + "&mdseId=" + document.eventmaintenance.mdseId.value + "&buId=&xxxmdseId=&xxxbuId=";
            //alert(url);
            window.location = url;
      } else { //Save event so they can choose item group for impact
            if (validateForm()) {
                  var action;
                  if (which=="store") {
                        action="SSEFGS";
                  } else {
                        action="ISEFGS";
                  }
                  document.eventmaintenance.Action.value=action;
                  document.eventmaintenance.submit();
            }
      }
}

</script>
There are t <form> tags, please ignore one of them, I made mistake during editting.
<a class=bold href="javascript:chooseGroups('item','-1')">Item group</a>

could you give this tag a "name" property/value?

like this:

<a name="lnkGroup" class=bold href="javascript:chooseGroups('item','-1')">Item group</a>

that would help a lot.
wtconway,

I think something is wrong with the loop below, but I am not sure how to fix it.

==================================================================
IHTMLElementCollection eventLinks = myDoc.getElementsByTagName("a");
int i = 0;

foreach (HTMLAnchorElementClass el in eventLinks)
{
     i++;
     Console.WriteLine(i.ToString() + " : " + el.outerText);
     if (el.outerText.Trim() == "Item Group")
     {
        el.click();
      Task++;
                break;
      }
}
==================================================================

It finds 137 links proven by eventLinks.length = 137 , but i only goes to 49 and el.outerText for 49 is empty.
More details. There are 7 links (A,B,C,D,E,F,G) go horizontally across the top of the webpage, if you hover on three of them (B,C,D), you will get a list of links that you can click. The rest of the links are somewhere in the page.
The loop only goes to the 7 links and and the links that are listed under B, which sums up to only 48 links.

Do you know what might have gone wrong?

Thanks for your help so far.


I ask again: can you name this link? Do you control the output of this page or does this page belong to someone else?

And I believe that should be

el.innerText.Trim() == "Item Group"
Wtconway,

That page belongs to someone else.
I tried innerText, it outputs the same thing as outerText.
amuse me, try this:

el.innerText.Trim().ToLower == 'item group'

see if that works.
Sorry,
still to no avail. :(
The only difference is in the console it outputs only to 48.
can I have the url to the page? I want to try my own code against it...see if I can figure this out.

I would like to, but I really can't since you need to login to get to the problematic page.
I think I will try to create a webpage that duplicate the original one.
The author of the page puts the each list of links for B,C,D in separate tables and the other links in different tables, and I think this causes the problem.
Let me recreate the page then.
I tried to duplicate the code, but it won't work like the original page.
So, I editted the HTML code as little as I can and came up with this.
I stripped the javascript functions on the bottom except the ones that "item group" needs to function.
Other javascript functions that are invoked from href are written internally, because I don't see them anywhere in the source code.
Hope this is helpful for you to help me solving the problem
Thank you!

<meta http-equiv='content-type' content='text/html; charset=windows-1252'>
<HTML><HEAD><TITLE>Event </TITLE>
<STYLE>
.superDark{
      font-family:arial;
      font-size:8pt;
      color:#FFFFFF;
      text-decoration:none;
      font-weight:bold;
}
.superDarkU{
      font-family:arial;
      font-size:8pt;
      color:#FFFFFF;
      font-weight:bold;
}
.myNormal{
      font-family:arial;
      font-size:8pt;
      color:#000000;
}
.myBold{
      font-family:arial;
      font-size:8pt;
      font-weight:bold;
      color:#000000;
}
.myError{
      font-family:arial;
      font-size:10pt;
      font-weight:bold;
      color:Red;
}
.grid{border-width:.1em;border-color:#a0a0a0;border-bottom-style:solid;border-top-style:none;border-right-style:solid;border-left-style:none;}.gridlower{border-width:.1em;border-color:#a0a0a0;border-bottom-style:solid;border-top-style:none;border-right-style:none;border-left-style:none;}</STYLE>
<LINK REL="stylesheet" TYPE="text/css" HREF="/styles/site_styles.css">
<Script Language=JavaScript src="/include/common_client_scriptLib.js"></SCRIPT>
<Script Language=JavaScript src="/xxxx/include/xxxx_common.js"></SCRIPT>
</HEAD>
<BODY LEFTMARGIN="0" TOPMARGIN="0" MARGINWIDTH="0" MARGINHEIGHT="0">
<script language="Javascript" src="/include/dropmenu.js"></script>
<!-- BEGIN HEADER HTML -->
<p id="TopRow0"  style="border-right: thin solid #707070;"  class="htrn">
<a class="htr" onmouseover="displayMenu('0'); hoverMenu(this);" href="/home/default.asp">Main Link A&nbsp;&nbsp;</a></p>
<p id="TopRow1"  style="border-right: thin solid #707070;"  class="htrn">
<a class="htr" onmouseover="hoverMenu(this); displayxxMenu('1');" onmouseout="clearxxHeaderTimeout();" href="#">Main Link B&nbsp;&nbsp;</a></p>
<p id="TopRow2"  style="border-right: thin solid #707070;"  class="htrn">
<a class="htr" onmouseover="hoverMenu(this); displayxxMenu('2');" onmouseout="clearxxHeaderTimeout();" href="#">Main Link C&nbsp;&nbsp;</a></p>
<p id="TopRow3"  style="border-right: thin solid #707070;"  class="htrn">
<a class="htr" onmouseover="hoverMenu(this); displayxxMenu('3');" onmouseout="clearxxHeaderTimeout();" href="#">Main Link D&nbsp;&nbsp;</a></p>
<p id="TopRow4"  style="border-right: thin solid #707070;"  class="htrn">
<a class="htr" onmouseover="displayMenu('4'); hoverMenu(this);" href="/xxhome/site_map.aspx">Main Link E&nbsp;&nbsp;</a></p>
<p id="TopRow5"  style="border-right: thin solid #707070;"  class="htrn">
<a class="htr" onmouseover="displayMenu('5'); hoverMenu(this);" href="/custom/personalize.asp">Main Link F&nbsp;&nbsp;</a></p>
<p id="TopRow6"  class="htrn">
<a class="htr" onmouseover="displayMenu('6'); hoverMenu(this);" href="/xx_security/xx_logoff.aspx?logoff=Y">Main Link G&nbsp;&nbsp;</a></p>
<script language="javascript"> arrange(); </script>
<div id="theDiv" class="menuMain">
<table id="MenuB" bgColor="#E0E0E0" style="display:none;">
<tr><td><a href="PageA.aspx" class="hmi">PageA</a></td></tr>
<tr><td><a href="PageB.aspx" class="hmi">PageB</a></td></tr>
<tr><td><a href="PageC.aspx" class="hmi">PageC</a></td></tr>
<tr><td style="border-top: thin outset white" width=100%>
      <table>
                      <tr>
                  <td>
                        <a href="javascript:openWinNoURL('/home/site_map.aspx?custom=Y&selkey=H200','siteMap',600,500)"></a>
                  </td>
                  <td valign="middle">
                        <a style="font-weight: bold;" class="hmi" href="javascript:openWinNoURL('/home/site_map.aspx?custom=Y&selkey=H200','siteMap',600,500)">&nbsp;Add/Remove</a>
                  </td>
            </tr>
      </table>
      </td>
</tr>
</table>

<table id="MenuC" bgColor="#E0E0E0" style="display:none;">

<tr><td><a href="PageA.aspx" class="hmi">PageA</a></td></tr>
<tr><td><a href="PageB.aspx" class="hmi">PageB</a></td></tr>
<tr><td><a href="PageC.aspx" class="hmi">PageC</a></td></tr>

<tr><td style="border-top: thin outset white" width=100%>
            <table>
                  <tr>
                        <td>
                              <a href="javascript:openWinNoURL('/home/site_map.aspx?custom=Y&selkey=H201','siteMap',600,500)"></a>
                        </td>
                        <td valign="middle">
                              <a style="font-weight: bold;" class="hmi" href="javascript:openWinNoURL('/home/site_map.aspx?custom=Y&selkey=H201','siteMap',600,500)">&nbsp;Add/Remove</a>
                        </td>
                  </tr>
            </table>
      </td>
</tr>
</table>

<table id="MenuD" bgColor="#E0E0E0" style="display:none;">
<tr><td><a href="PageA.aspx" class="hmi">PageA</a></td></tr>
<tr><td><a href="PageB.aspx" class="hmi">PageB</a></td></tr>
<tr><td><a href="PageC.aspx" class="hmi">PageC</a></td></tr>

<tr><td style="border-top: thin outset white" width=100%>
            <table>
                  <tr>
                        <td>
                              <a href="javascript:openWinNoURL('/home/site_map.aspx?custom=Y&selkey=H204','siteMap',600,500)"></a>
                        </td>
                        <td valign="middle">
                              <a style="font-weight: bold;" class="hmi" href="javascript:openWinNoURL('/xxhome/site_map.aspx?custom=Y&selkey=H204','siteMap',600,500)">&nbsp;Add/Remove</a>
                        </td>
                  </tr>
            </table>
      </td>
</tr>
</table>
</div>
<iframe  id="DivShim" src="javascript:false;"  scrolling="no" frameborder="0" style="position:absolute; top:10px; left:10px; display:none; z-index: 0;"></iframe>
<table width="100%">
      <tr>
            <td valign="bottom" width="80%">
                  <table celpadding=0 cellspacing=0 width="100%">
                        <tr>
                              <td width=10% bgColor="navy" class="header10-s">&nbsp;Search:&nbsp;</td>
                              <td bgColor="navy" width="300px">
                                    <input id="searchField" onKeyPress="return submitenter(this,event)" class="formfield" style="width:300px; border: none;"
                              </td>
                              <td width=50% bgColor=navy style="filter:alpha(opacity=100, finishopacity=0, style=1, startx=0, starty=0, finishx=140, finishy=270"><input onclick="submitSearch();" type="button" class="formbutton9-p" value="GO">
                              </td>
                        </tr>
                  </table>
            </td>
            <td align="right"><a href="/default.asp?ch=homeU2"></a>
            </td>
      </tr>
      <tr>
            <td>
                  <table width="100%">
                        <tr>
                              <td width="33%" class="header10-p">Irma's</td>
                              <td class="header10-q"></td>
                        </tr>
                  </table>
            </td>
            <td class="header10-p" align="right">xx Week: <script language=javascript>displayxxWeek();</script>
            </td>
      </tr>
      <tr>
            <td></td>
      </tr>
</table>
<div id="topper" onmouseover="DivSetVisible(false, document.getElementById('theDiv'), 0);" style="position:absolute; top: 1; left:1; width:100%; height:1px;"></div>
<div id="RLmain" onmouseover="DivSetVisible(false, document.getElementById('theDiv'), 0);" style="postition:block;"><script language=javascript>showLogo();</script>
<!-- END HEADER HTML -->

<table height="100%" width="100%" cellpadding=0 cellspacing=0 border=0>
<TR width="100%">\
      <td valign="top" width="150">
            <table border="0" height="100%" cellpadding="0" cellspacing="0"  width="100%">
            <tr>
                  <TD width="1" height="5" cellpadding="0" cellspacing="0" class="HomeTopMenuBackground"></td>
                  <td valign="top">
                        <table border="0" height="100%" cellpadding="0" cellspacing="0"  width="100%">
                              <tr>
                                    <script language="javascript" src="/home/xx_header.asp?userid=xxx&language=ENG&flag=5&userkey=U2">
                                    </script>
                              </tr>
                              <tr>
                                    <td valign="top"  width="150" NOWRAP >
                                          <DIV class="normal">&nbsp;</DIV>
                                          <DIV class="lefthead">Collaboration</DIV>
                                          <DIV class="normal">&nbsp;&nbsp;&nbsp;&nbsp;<A class="normal" HREF="/xxxx/notification/fcst_notification.asp?ch=H3&div=1&appType=xxxx">Notification</A></DIV>
                                          <DIV class="normal">&nbsp;&nbsp;&nbsp;&nbsp;<A class="normal" HREF="/xxxx/itemselection/item_search.asp?ch=H3&div=1">Item Selection</A></DIV>
                                    </td>
                              </tr>
                              <tr>
                                    <td>
                                          <form name="eventmaintenance" action="/xxxx/xxx/event_maintenance.asp?ch=H3&div=1&appType=xxxx" method="POST">
                                          <table width="100%" bgcolor='#ffffff' border="0">
                                                <input type=Hidden name='Action'>
                                                <input type=Hidden name='EventId' value="-1">
                                                <input type=Hidden name='ParentId' value="">
                                                <input type=Hidden name='CopyFromEventId' value="">
                                                <input type=Hidden name='OldEventId' value="-1">
                                                <input type=Hidden name='Level' value="">
                                                <input type=Hidden name='OwnerId' value="xxx">
                                                <tr>
                                                      <td align="CENTER" valign="MIDDLE" class="subDark" bgcolor="#3366FF">Describe Event</td>
                                                </tr>
                                                <tr>
                                                      <td>
                                                            <table width="100%" border="0">
                                                                  <tr>
                                                                        <td class="sub">Name:</td>
                                                                        <td><input type="Text" name="EventName" value="" maxlength="40" size="20"></td>
                                                                        <td class="sub">Description</td>
                                                                        <td ><input type="Text" name="EventDesc" value="" maxlength="255" size="45"><br><font size=-3>(max of 255 characters)</font></td>
                                                                  </tr>
                                                                  <tr>
                                                                        <td>
                                                                              <table width="100%" cellpadding="0" cellspacing="0" border="0">
                                                                                    <tr>
                                                                                          <td class="sub"></td>
                                                                                                <input size="9" name="mdseId" value="" type="text">
                                                                                                <input name="mdseDesc" size="30" type="text" value="">&nbsp;
                                                                                                <a class=bold href="javascript:chooseGroups('item','-1')">Item Group</a>
                                                                                          <td></td>
                                                                                    </tr>      
                                                                              </table>
                                                                        </td>            
                                                                  </tr>
                                                            </table>
                                                      </td>
                                                </tr>
                                          </table>
                                    </form>
                              </td>
                        </tr>
                  </table>
            </td>
      </tr>
</table>
<script language="javascript" src="/home/xx_footer.asp?language=ENG&country=US"></script>
</body>
</html>
<SCRIPT LANGUAGE="JavaScript">
function chooseGroups(which,EventId) {
     if (EventId!="-1") {
          var url = "/xxx/xxx/" + which + "_group.asp?ch=H3&div=1&appType=xxx&EventId=-1&mdseLevel=" + document.eventmaintenance.mdseLevel.value + "&mdseId=" + document.eventmaintenance.mdseId.value + "&buId=&xxxmdseId=&xxxbuId=";
          //alert(url);
          window.location = url;
     } else { //Save event so they can choose item group for impact
          if (validateForm()) {
               var action;
               if (which=="store") {
                    action="SSEFGS";
               } else {
                    action="ISEFGS";
               }
               document.eventmaintenance.Action.value=action;
               document.eventmaintenance.submit();
          }
     }
}

function validateForm() {
     var bGood = true;
     //Check Describe Event
     if (document.eventmaintenance.EventTypeCode.options[document.eventmaintenance.EventTypeCode.selectedIndex].value=="") { bGood=false; }
     if (RTrim(document.eventmaintenance.EventDesc.value)=="") { bGood=false; }
     if (RTrim(document.eventmaintenance.EventName.value)=="") { bGood=false; }
     if (!bGood) { alert("Fill in all Event Description fields."); }

     //Check Time Occurance
     if (document.eventmaintenance.OccuranceType[0].checked) { //Once
          var begin = new Date(document.eventmaintenance.BeginDateMM.options[document.eventmaintenance.BeginDateMM.selectedIndex].value + "/" + document.eventmaintenance.BeginDateDD.options[document.eventmaintenance.BeginDateDD.selectedIndex].value + "/" + document.eventmaintenance.BeginDateYYYY.options[document.eventmaintenance.BeginDateYYYY.selectedIndex].value);
          var end = new Date(document.eventmaintenance.EndDateMM.options[document.eventmaintenance.EndDateMM.selectedIndex].value + "/" + document.eventmaintenance.EndDateDD.options[document.eventmaintenance.EndDateDD.selectedIndex].value + "/" + document.eventmaintenance.EndDateYYYY.options[document.eventmaintenance.EndDateYYYY.selectedIndex].value);
         
          if (end < begin) {
               alert("Event End Date must be after Event Begin Date.");
               bGood = false;
          }

     } else if (document.eventmaintenance.OccuranceType[1].checked) { //Annual
          if (document.eventmaintenance.AnnuallyType[0].checked) { //Exact Day
               if (document.eventmaintenance.SpecificDateMonth.options[document.eventmaintenance.SpecificDateMonth.selectedIndex].value=="-1" || document.eventmaintenance.SpecificDateDay.options[document.eventmaintenance.SpecificDateDay.selectedIndex].value=="-1") {
                    alert("Choose Exact Day Info.");
                    bGood=false;
               }
          } else if (document.eventmaintenance.AnnuallyType[1].checked) { //Day of Week
               if (document.eventmaintenance.DayWhichWeek.options[document.eventmaintenance.DayWhichWeek.selectedIndex].value=="-1" || document.eventmaintenance.DayWhichDay.options[document.eventmaintenance.DayWhichDay.selectedIndex].value=="-1" || document.eventmaintenance.DayWhichMonth.options[document.eventmaintenance.DayWhichMonth.selectedIndex].value=="-1") {
                    alert("Choose Day of Week Info.");
                    bGood=false;
               }
          } else if (document.eventmaintenance.AnnuallyType[2].checked) { //Holiday
               if (document.eventmaintenance.HolidayCode.options[document.eventmaintenance.HolidayCode.selectedIndex].value=="-1") {
                    alert("Choose Holiday Info.");
                    bGood=false;
               }
          } else {
               alert("Fill in Event Time Occurrance.");
               bGood = false;
          }

          if (document.eventmaintenance.DaysBeforeEvent.value==""||document.eventmaintenance.DaysAfterEvent.value=="") {
               alert("Fill in Before/After Days fields.");
               bGood = false;
          }
          if (document.eventmaintenance.RemindDays.value=="") {
               alert("Fill in Remind Days.");
               bGood = false;
          }
          if (!document.eventmaintenance.EndCode[0].checked && !document.eventmaintenance.EndCode[1].checked) {
               alert("Select when event ends.");
               bGood = false;
          }
          if (document.eventmaintenance.EndCode[1].checked && document.eventmaintenance.OccurranceCount.value=="") {
               alert("Choose in how many years the Event will end.");
               bGood = false;
          }
          document.eventmaintenance.DaysBeforeEvent.value = document.eventmaintenance.DaysBeforeEvent.value.replace(",","");
          document.eventmaintenance.DaysAfterEvent.value = document.eventmaintenance.DaysAfterEvent.value.replace(",","");
          document.eventmaintenance.RemindDays.value = document.eventmaintenance.RemindDays.value.replace(",","");
          document.eventmaintenance.OccurranceCount.value = document.eventmaintenance.OccurranceCount.value.replace(",","");
          if (!isRealNumber(document.eventmaintenance.DaysBeforeEvent.value)||!isRealNumber(document.eventmaintenance.DaysAfterEvent.value)||!isRealNumber(document.eventmaintenance.RemindDays.value)||!isRealNumber(document.eventmaintenance.OccurranceCount.value)) {
               alert("Time Occurrance Fields must be whole numbers.");
               bGood = false;
          }
     }
     return bGood;
}


</script>
It doesn't look like I can reproduce the page...i don't have copies of CSS and Javascript files you guys are referencing. I'm pretty sure that the dynamically added links and such are causing the problem, however.

Which link is it that will cause the other links to appear? And it is one of these appearing links you want to click?
Wtconway,

The link that I want to click is already on the page and it is on the HTML that I posted above. It looks like this:
 <a class=bold href="javascript:chooseGroups('item','-1')">Item Group</a>

Since this webpage is not mine, I don't have the copies of CSS and javascript files either. :(
Wtconway,

I found the root of the problem...
the 49th link is an image, thus I can't use innertext  or outertext to use in comparison...
When I tried link.href as you recommended, there are some codes that still uses outerText. That's why it failed....
So using .href is safer than innerText or outerText.
Thank you for the help....
No problem...well at least you know how to do it now.