Results 1 to 10 of 10

Thread: [resolved]document.Form

  1. #1

    Thread Starter
    Addicted Member jewel's Avatar
    Join Date
    Jul 2003
    Location
    truly asia
    Posts
    153

    [resolved]document.Form

    I need to get the value of a form element by using

    document.Form1.txtName.value

    I get an error when I use this on a web user control...

    So I tried putting form tag in the html code still, it doesn't work dunno why, maybe its because I didn't put runat="server" but if I put this the page will return an error saying that it cannot allow two runat="server"

    anyone?

    Please help...


    Thanks,

    Jewel
    Last edited by jewel; Aug 4th, 2005 at 12:25 AM.
    xoxo

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: document.Form

    Take a look at txtName's ID attribute when viewing the page in a browser. It has most likely changed when being rendered.

  3. #3

    Thread Starter
    Addicted Member jewel's Avatar
    Join Date
    Jul 2003
    Location
    truly asia
    Posts
    153

    Re: document.Form

    how?

    Thanks,

    Jewel
    xoxo

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: document.Form

    Open page in browser (run application) then in your browser, Edit > View Source.

  5. #5
    Frenzied Member dj4uk's Avatar
    Join Date
    Aug 2002
    Location
    Birmingham, UK Lobotomies: 3
    Posts
    1,131

    Re: document.Form

    Either look in the HTML source as Mendhak says or you can access the client-side ID of a control from the ClientID property i.e. txtName.ClientID

    DJ

    If I have been helpful please rate my post. If I haven't tell me!

  6. #6

    Thread Starter
    Addicted Member jewel's Avatar
    Join Date
    Jul 2003
    Location
    truly asia
    Posts
    153

    Re: document.Form

    hi, yes it changed it to MyControl1:sName because I embedded it as a web user control with name MyControl1, so I used this in the script

    HTML Code:
    alert (document.all["MyControl1:sName"].value );
    however this will be a problem when I reuse the control under a different name...

    any other suggestions?

    Thanks,

    Jewel
    xoxo

  7. #7
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: document.Form

    Generate your javascript from codebehind and use controlname.ClientId in there.

  8. #8

    Thread Starter
    Addicted Member jewel's Avatar
    Join Date
    Jul 2003
    Location
    truly asia
    Posts
    153

    Re: document.Form

    do you mean generate javascript from codebehind then use RegisterStartupScript? but this is not available for user control, right?

    hmmm...


    Thanks,

    Jewel
    xoxo

  9. #9

    Thread Starter
    Addicted Member jewel's Avatar
    Join Date
    Jul 2003
    Location
    truly asia
    Posts
    153

    Re: document.Form

    This works

    VB Code:
    1. Dim strScript As String = "alert (document.all['" & MyClass.ClientID & "_sName'].value );"
    2.         btnOk.Attributes.Add("onclick", strScript)

    Thanks,

    I wont put resolved yet coz i don't know if another problem would sneak in...
    Last edited by jewel; Aug 3rd, 2005 at 10:36 PM.
    xoxo

  10. #10
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: document.Form

    If another problem comes up, you can post a new thread.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width