0

I try upgrade code from IE to chrome and this function can't set text and value from combobox

This is my click function

function onClick_ListItem() {
if (event.srcElement.tagName == "TD") {
    var tempobject = event.srcElement;
    while (tempobject.tagName != "DIV") {
        tempobject = tempobject.parentElement;
    }
    var tempstr = tempobject.id.substring(0, tempobject.id.lastIndexOf('_') + 1);
    eval("document.all." + tempstr + "InputText").value = event.srcElement.parentElement.text;
    eval("document.all." + tempstr + "SelectedValue").value = event.srcElement.parentElement.value;
    eval("document.all." + tempstr + "ListItem").style.display = "none";
}

} This is chrome picture

This is ComboBox.ascx code

<table id="ControlHandle" style="BORDER-RIGHT: #0099cc 1px solid; PADDING-RIGHT: 0px; BORDER-TOP: #0099cc 1px solid; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; BORDER-LEFT: #0099cc 1px solid; PADDING-TOP: 0px; BORDER-BOTTOM: #0099cc 1px solid"
cellSpacing="0" cellPadding="0" width="300" runat="server">
<tr width="100%">
    <TD><INPUT id="InputText" onblur="onblur_InputText(this)" style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BORDER-LEFT: medium none; WIDTH: 100%; BORDER-BOTTOM: medium none; BACKGROUND-COLOR: #ffffff"
            type="text" maxLength="200" onchange="onchange_InputText()" name="InputText" runat="server"></TD>
    <TD style="BORDER-LEFT: #0099cc 1px solid" onclick="ControlListItem(this)" align="center"
        width="17" bgColor="#c9ddf5"><IMG src="downarrow.gif" align="middle"></TD>
</tr>
<tr>
    <td colSpan="2"><input id="SelectedValue" type="hidden" name="SelectedValue" runat="server"><input id="TempRowIndex" type="hidden" name="TempRowIndex" runat="server"></td>
</tr>
<div onmousemove="mouseMove_ListItem()" id="ListItem" style="BORDER-RIGHT: #0099cc 1px solid; PADDING-RIGHT: 1px; BORDER-TOP: medium none; OVERFLOW-Y: scroll; DISPLAY: none; SCROLLBAR-FACE-COLOR: #c9ddf5; BORDER-LEFT: #0099cc 1px solid; WIDTH: 300px; SCROLLBAR-SHADOW-COLOR: #0099cc; SCROLLBAR-3DLIGHT-COLOR: #0099cc; SCROLLBAR-ARROW-COLOR: #0099cc; SCROLLBAR-TRACK-COLOR: #f0f8ff; BORDER-BOTTOM: #0099cc 1px solid; SCROLLBAR-DARKSHADOW-COLOR: #f0f8ff; HEIGHT: 100px; BACKGROUND-COLOR: #f4f8ff"
onclick="onClick_ListItem()" onmouseout="mouseout_ListItem()" runat="server" onchange="onchange_InputText()" >
<asp:datagrid id="DataGrid_ListItem" runat="server" AutoGenerateColumns="False" Width="100%"></asp:datagrid>
  • You forgot to accept the `event` inside the function. – Tehila Oct 13 '22 at 00:48
  • Where should i put it on function? sorry i'm noob on JS – willy99924 Oct 13 '22 at 00:54
  • You should accept it as an argument between the `()` like this: `function onClick_ListItem(event)`. And also , can you show me the code where you trigger this function on the button? – Tehila Oct 13 '22 at 00:58
  • I am try add event on function but it no work should I add something on combox.ascx? – willy99924 Oct 13 '22 at 01:15
  • Okay, so **first**, you need to **call** the function from the `div` element and send the event, like this: `
    ...
    `. **Second**, you need to accept the `event` as an argument in the function you called. like this: `function onClick_ListItem(event) {...} `. See this [link](https://stackoverflow.com/questions/1276870/how-to-pass-an-event-object-to-a-function-in-javascript) for how to use onclick and pass the `event`.
    – Tehila Oct 13 '22 at 01:29
  • But my code doesn't use button to call function it work like this https://imgur.com/a/xJKQmIa – willy99924 Oct 13 '22 at 01:40
  • What I mean is that wherever you call this function in your HTML - send the `event` : `onclick="onClick_ListItem(event)"`. And in your javascript function - accept it: `function onClick_ListItem(event) {....}`. – Tehila Oct 13 '22 at 02:04

0 Answers0