www.webdeveloper.com
Results 1 to 12 of 12

Thread: jscript runtime error

  1. #1
    Join Date
    Aug 2004
    Posts
    8

    jscript runtime error

    i've attached the my code for opening a window vich has a calendar & buttons ...& the selected date on this window is used in another form....

    i'm getting the jscript runtime error:object expected
    cud someone please go through the code & help me out
    Attached Files Attached Files

  2. #2
    Join Date
    Jul 2004
    Location
    London
    Posts
    284
    Maybe you could tell us when the error occurs? Not having an ASP host makes it hard to run the code you attached. Maybe you have it online at a URL we can visit?

    The only JavaScript I would change is the first line in your SetDate function... From this:

    Code:
    eval('var theform = document.' + formName + ';');
    to this:

    Code:
    var theform = document.forms[formName];
    Hope this helps,
    Dan

  3. #3
    Join Date
    Aug 2004
    Posts
    8
    it hasnt worked ...i'm still gettin the same error...the error is occuring in that setdate function only ....
    anyways...thanx for the help

  4. #4
    Join Date
    Jul 2004
    Location
    London
    Posts
    284
    You haven't shown the code where SetDate is being called. Maybe the ID you're passing in doesn't exist as the name of a form element?

    Dan

  5. #5
    Join Date
    Aug 2004
    Posts
    8
    this is my setdate function....

    function SetDate(formName, id, newDate, postBack)
    {
    eval('var theform = document.' + formName + ';');
    popUp.close();
    theform.elements[id].value = newDate;
    if (postBack)
    __doPostBack(id,'');
    }

  6. #6
    Join Date
    Jul 2004
    Location
    London
    Posts
    284
    I know - you already posted it. What you didn't post is where it is being called from.

    Dan

  7. #7
    Join Date
    Aug 2004
    Posts
    8
    o...sorry...i misread ur messg...

    i wrote it in the code behind for my calendar window...adding an attribute to the button...onclick & called the function setdate

  8. #8
    Join Date
    Jul 2004
    Location
    London
    Posts
    284
    OK - we'll play it your way. If you won't post the code surrounding the call to the SetDate function, perhaps you can tell us whether or not the IDs you are passing into the setDate function exist as valid form element names.

    Come on - help us to help you!

    Dan

  9. #9
    Join Date
    Aug 2004
    Posts
    8
    This is my code behind

    Public Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    'Put user code to initialize the page here
    If Not Page.IsPostBack Then
    Dim selected As String = Request.QueryString("selected")
    Dim id As String = Request.QueryString("id")
    Dim form As String = Request.QueryString("formname")
    Dim postBack As String = Request.QueryString("postBack")

    Try
    Cal.SelectedDate = CDate(selected)
    Cal.VisibleDate = Cal.SelectedDate
    Catch
    Cal.SelectedDate = DateTime.Today
    Cal.VisibleDate = Cal.SelectedDate
    End Try


    SelectCorrectValues()


    OKButton.Attributes.Add("onClick", "window.opener.SetDate('" + form + "','" + id + "', document.Calendar.datechosen.value," + postBack + ");")

    CancelButton.Attributes.Add("onClick", "CloseWindow()")
    End If

    End Sub 'Page_Load

    Public Sub SelectCorrectValues()
    lblDate.Text = Cal.SelectedDate.ToShortDateString()
    datechosen.Value = lblDate.Text

    End Sub 'SelectCorrectValues

    Public Sub Cal_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cal.SelectionChanged
    Cal.VisibleDate = Cal.SelectedDate
    SelectCorrectValues()
    End Sub 'Cal_SelectionChanged

    End Class

    OKButton.Attributes.Add("onClick", "window.opener.SetDate('" + form + "','" + id + "', document.Calendar.datechosen.value," + postBack + ");")

  10. #10
    Join Date
    Jul 2004
    Location
    London
    Posts
    284
    So we are still none the wiser as to what "id" is being passed in as.

    How about you debug the code with alert statements, and find out what "id" is being passed in as - and then see if it is a valid form element name.

    Hope this helps,
    Dan

  11. #11
    Join Date
    Aug 2004
    Posts
    8
    id is passed in as txtdate
    form as .... Form1...
    newdate as..... selected date in the cal
    postback....true
    i dont see anything wrong in the values passed to the setdate...

  12. #12
    Join Date
    Jul 2004
    Location
    London
    Posts
    284
    Both your form and form elements have ID attributes but no NAME attribute. I'd suggest adding name="Form1" to your form tag and name="txtDate" to your textbox.

    Furthermore, JS is case sensitive, so passing "txtdate" when the name is "txtDate" will not work.

    Hope this helps,
    Dan

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles