Arun:
First off, since you are working on an asp.net page, ASP.Net is naming the
control something other than
"TextBox1" when it renders it on the page. In order to get past this, we
need to find a way to tell
javascript the true name of the control as it is finally rendered on the
page, or just pass a reference to the
actual control.
I am not sure where you are calling the "con_date()" javascript function,
but
I will assume it is on the onchange event of "TextBox1"
Here is how I would accomplish what you are wanting:
Change the con_date() function to accept an object like so:
function con_date(txtBox)
{
var ddmmyy= txtBox.value;
var dd = ddmmyy.substring(0,2);
var mm = ddmmyy.substring(2,4);
var yy = ddmmyy.substring(4,8);
txtBox.value = mm + "/" + dd + "/" + yy;
}
(This also allows you to reuse this function for multiple textboxes on the
page as well)
Then, for your onchange event of the textbox, change it to this:
con_date(this);
That should do the trick.
Let me know how it works out.
You could also accomplish the same thing in the ASP.net code by writing the
javascript function
there and passing the TextBox1.ClientID, but I thought based on your current
code this would be easier than
trying to spit out all the javascript code from the ASP.net side.
Just for future reference, here is an example of what I am talking about:
If txtAddDDLItem.Text <> "" And hdnAddDDLItem.Value <> "" Then
Dim ddl As DropDownList = tblAdd_Employee.FindControl(
hdnAddDDLItem.Value)
ddl.Items.Add(txtAddDDLItem.Text.ToString())
ddl.SelectedValue = txtAddDDLItem.Text
ClientScript.RegisterStartupScript(Me.GetType(), "theFocus", "<script>
document.getElementById('" & ddl.ClientID & "').focus();</script>")
End If
Basically, this code uses RegisterStartupscript to add a small script that
sets the focus to a particular control.
--
[EMAIL PROTECTED]
On 9/12/06, Arun Arora <[EMAIL PROTECTED]> wrote:
>
> Hi Brett,
>
> Many thanks on the prompt response....here is the code with the
> problem....it seems that as soon as i want to get the value out of the
> textbox1 it gives an error.....document.getelementbyid("textbox1").value
> does'nt work here then what will....i have run out of all ideas....all i
> want to do is to take the value from the textbox....manipulate it and then
> put it back in the same textbox...the code is as follows:
>
> <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"
> Runat="Server">
> <script type="text/javascript">
> function con_date()
> {
> var ddmmyy= document.getElementById("TextBox1").value;
> var dd = ddmmyy.substring(0,2);
> var mm = ddmmyy.substring(2,4);
> var yy = ddmmyy.substring(4,8);
> document.getElementById("textbox1").value = mm + "/" + dd + "/" + yy;
> }
> function num_chk()
> {
> var a = document.getElementById("textbox1").value;
> if (a == "")
> {
> alert("THIS FIELD CANNOT BE LEFT BLANK");
> document.form1.textbox1.focus();
> }
> }
> </script>
> <strong><span style="color: #ff3300"><span style="text-decoration:
> underline">Please
> Enter Cut-Off Date</span>:</span></strong>
> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
> <asp:Button ID="Button2" runat="server" Font-Bold="True"
> OnClick="Button2_Click"
> Text="Run Report" />
>
> <asp:Button ID="Button3" runat="server" Font-Bold="True"
> OnClick="Button3_Click"
> Text="Cancel Report" /><br />
> <br />
> <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
> Text="Export To Excel" Font-Bold="True" /><br />
> <br />
> <asp:GridView ID="GridView1" runat="server" BackColor="White"
> BorderColor="#CC9966"
> BorderStyle="None" BorderWidth="1px" CellPadding="4">
> <FooterStyle BackColor="#FFFFCC" ForeColor="#330099" />
> <RowStyle BackColor="White" ForeColor="#330099" />
> <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="#663399"
> />
> <PagerStyle BackColor="#FFFFCC" ForeColor="#330099"
> HorizontalAlign="Center" />
> <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="#FFFFCC" />
> </asp:GridView>
> </asp:Content>
>
> eagerly awaiting your comments and suggestions on this,
>
> regards,
>
> Arun.
>
>
> Brett Stinson <[EMAIL PROTECTED] <brett.stinson%40gmail.com>> wrote:
> Arun:
> It sounds as if the javascript is where the error is, especially if the
> error happens wherever you try to use the javascript. Can you post the
> code
> so we can try to help debug it?
>
> --
> [EMAIL PROTECTED] <Brett.Stinson%40gmail.com>
>
> On 9/12/06, Arun <[EMAIL PROTECTED] <darun_arora%40yahoo.com>> wrote:
> >
> > hi all,
> >
> > i would like to convery thanks in advance....hare is my problem....
> >
> > i have a master page in the main directory and content pages in a
> > folder.......i have tried to put the javascript functions on the
> > content page but generates error....i have also tried to put it on the
> > master page but generates error.......please guide me how to make this
> > work
> >
> > thanks in advance again......
> >
> > arun arora
> > .
> >
> >
> >
>
> [Non-text portions of this message have been removed]
>
>
> ---------------------------------
> Do you Yahoo!?
> Everyone is raving about the all-new Yahoo! Mail.
>
> [Non-text portions of this message have been removed]
>
>
>
[Non-text portions of this message have been removed]
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/AspNet2/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/AspNet2/join
(Yahoo! ID required)
<*> To change settings via email:
mailto:[EMAIL PROTECTED]
mailto:[EMAIL PROTECTED]
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/