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 MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

accessing javascript function in a web user control

Status
Not open for further replies.

toptomato

Programmer
Jul 22, 2005
62
US
Hi,
thanks in advance to all those who will help
so i created a web user control that has two html input boxes in it. I also have the following java function in the ascx file (not the code behind file). Once implemented the page give me error when i enter the 3 number on in the first input box.


<script language="javascript">
<!--
function autotab(original, destination){
if(original.getAttribute&&original.value.length==original.getAttribute("maxlength")) destination.focus()
}
-->
</script>

<INPUT class="tb24x16" id="html_tb_ph1_1" onkeyup="autotab(this, Form1.html_tb_ph1_2)" type="text" maxLength="3" size="1" name="html_tb_ph1_1" runat="server">

<INPUT class="tb24x16" id="html_tb_ph1_2" onkeyup="autotab(this, document.Form1.html_tb_ph1_3)" type="text" maxLength="3" size="1" name="html_tb_ph1_2" runat="server">

<INPUT class="tb32x16" id="html_tb_ph1_3" onkeyup="autotab(this, document.Form1.html_tb_ph1_4)" type="text" maxLength="4" size="1" name="html_tb_ph1_3" runat="server">

<INPUT class="tb32x16" id="html_tb_ph1_4" type="text" maxLength="4" size="1" name="html_tb_ph1_4" runat="server"></FONT></TD></TR>


 
>>autotab(this, Form1.html_tb_ph1_2)

how are u generating this? what does the javacript error say???

Known is handfull, Unknown is worldfull
 
autotab javascript function is in the html portion of the ascx file
there are no head tags in the ascx file so i have put it right the the input tags

I get the following javascript error:
Error: 'undefined' is not or not an object
Code: 0
 
If you use user control, control will be rendered in html as
_ctl0_ctlname ,_ctl1_ctlname etc. Check you html and access the object name accordingly.
Thanks and Regards
siva
 
ah,

i missed that out. but a good way to do this would be to use the form's elements collection or the DOM method's nextSibling() method...

Known is handfull, Unknown is worldfull
 
how would implement the autotab function using the form's elements collection
 
try this:

AllElements=document.forms.elements;
for(i=0;i<AllElements.length;i++)
{
alert(AllElements.name)
//using this you could track the field's name...
}

Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top