Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JavaScript not firing within a datagrid

Status
Not open for further replies.

LauraCairns

Programmer
Jul 26, 2004
173
0
0
GB
I've got this great wee function which strips out the spaces entered into a textbox and it does this on the key press off a user. I got this working in a test application no problem however when I went to intergrate it with my real application which has the textbox in the footer of a datagrid the javascript doesn't seem to run. Has anyone any idea why this is not working for me?

Any help would be much appreciated. Thanks

Here is the function and the textbox which I'm using

<script language="javascript" type="text/javascript">

<script language="javascript" type="text/javascript">
function CheckValidAdd(textbox, val)
{
val = val.replace(/[^0-9a-zA-Z]/g, '');
textbox.value = val;
}

</script>
<FooterTemplate>
<asp:TextBox ID="add_NINo" onKeyUp="CheckValidAdd(add_NINo, add_NINo.value);" Columns="5" Runat="Server" />
</FooterTemplate>
 
Have you checked the "view source" page and made sure it has the function assigned correctly to the onKeyUp event?

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
Laura: Was taking a look at this and I was able to get the java firing from the footer template:

Code:
<Html>
...
...
</HEAD>
<script language="javascript" type="text/javascript">
function CheckValidAdd(val)
{ 
    val = 3; 
    alert('value is =' + val)
}
</script>
<form runat="server">
<asp:DataGrid id="dgWS" showfooter="true" runat="server" AutogenerateColumns="false"  align="left" BorderColor="#CC9966" BorderStyle="None" BorderWidth="1px" BackColor="White" CellPadding="4">
<ItemStyle ForeColor="#330099" BackColor="white" Font-Size="9" ></ItemStyle>
<HeaderStyle Font-Size="10" horizontalalign="Center" verticalalign="Middle" ForeColor="#FFFFCC" BackColor="#990000"></HeaderStyle>
<Columns>
<asp:BoundColumn DataField="Name" HeaderText="WS"/>
<asp:BoundColumn DataField="TtlChemRecs" HeaderText="# Chem"/>
<asp:TemplateColumn>
<FooterTemplate>
<asp:TextBox ID="add_NINo" onKeyUp="javascript:CheckValidAdd(this.value);" Runat="Server" />
</FooterTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid> 
</form>
</body>
</html>

Just a few minor changes - at least the event is raised and the alert box pops up -- might be a hint here.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top