Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 14 of 14
  1. #1
    New Coder
    Join Date
    Dec 2004
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question object expected error?

    Hello

    I hava a javascript where object expected error is displayed. Below is the code.

    function get_check_value (check_array)
    {
    var CHKBOX='';
    var strmid='';
    var retNull='';
    var i;
    for (i = 0; i < check_array . length; ++ i)
    {
    if (check_array [i] . checked)
    CHKBOX=CHKBOX + ',' + check_array [i] . value;
    }
    strmid=mid(CHKBOX,2,CHKBOX.length);
    check_array=strmid=mid;
    return check_array;
    return retNull;
    }

    object expected error is shown at strmid=mid(CHKBOX,2,CHKBOX.length);
    What's the way out?

  • #2
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,535
    Thanks
    3
    Thanked 513 Times in 500 Posts
    Code:
     
    strmid=mid(CHKBOX,2,CHKBOX.length);
    check_array=strmid=mid;
    difficult to see what this is doing

    strmid is expecing a returned value from function mid

    CHKBOX is a string
    2 a digit
    CHECKBOX.length - the number of charactors of the string CHECKBOX

    check_array=the value of strmid;
    strmid = the value of mid;

    using mid as a variable name and also a function name is illegal

  • #3
    Regular Coder martin_narg's Avatar
    Join Date
    Jul 2002
    Location
    Chamonix, France
    Posts
    600
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Edit: Sorry vwphillips - we posted at the same time

    You've got a mish-mash opf vbscript and javascript with incorrect syntaxing in both mate - there's no Mid function in javascript - hence it's saying it can't be found.

    If you could post up what you are trying to do, then it would be much easier to supply a solution from scratch rather than using your existing function.

    Cheers!

    m_n
    Last edited by martin_narg; 08-13-2005 at 02:19 PM.
    "Cos it's strange isn't it. You stand in the middle of a library and go 'Aaaaaaaaaaaaaaaaggggggghhhhhhh!'
    and everybody just stares at you. But you do the same in an aeroplane, and everybody joins in."
    -Tommy Cooper

  • #4
    New Coder
    Join Date
    Dec 2004
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question

    just minor change in code, 'M' is caps & if 'Mid' is vbscript function then how to do in javascript?

    function get_check_value (check_array)
    {
    var CHKBOX='';
    var strmid='';
    var retNull='';
    var i;
    for (i = 0; i < check_array . length; ++ i)
    {
    if (check_array [i] . checked)
    CHKBOX=CHKBOX + ',' + check_array [i] . value;
    }
    strmid=Mid(CHKBOX,2,CHKBOX.length);
    check_array=strmid;
    return check_array;
    return retNull;
    }

    Thanks

  • #5
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,535
    Thanks
    3
    Thanked 513 Times in 500 Posts
    Edit: Sorry vwphillips - we posted at the same time
    happens all the time but seldom exactly the same time

  • #6
    Regular Coder
    Join Date
    Apr 2005
    Location
    Lisbon, CT
    Posts
    339
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by pashah72
    just minor change in code, 'M' is caps & if 'Mid' is vbscript function then how to do in javascript?

    function get_check_value (check_array)
    {
    var CHKBOX='';
    var strmid='';
    var retNull='';
    var i;
    for (i = 0; i < check_array . length; ++ i)
    {
    if (check_array [i] . checked)
    CHKBOX=CHKBOX + ',' + check_array [i] . value;
    }
    strmid=Mid(CHKBOX,2,CHKBOX.length);
    check_array=strmid;
    return check_array;
    return retNull;
    }

    Thanks
    Couple of things I see:
    for (i = 0; i < check_array . length; ++ i)
    I am not certain how this will evaluate in this context, but it seems that you will never check check_array[0]. It should be i++ unless this is what you intended to have happen.

    strmid = CHKBOX.substring(1,CHKBOX.length);

    Also, how exactly is check_array being generated?

    As someone already suggested perhaps more code would help, such as the checkbox portion of your form.

    BaldEagle

    [edit] Not butting in here as you all posted while I was writing my response.
    Last edited by BaldEagle; 08-13-2005 at 03:07 PM.

  • #7
    Regular Coder martin_narg's Avatar
    Join Date
    Jul 2002
    Location
    Chamonix, France
    Posts
    600
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Pasha72 - could you explain what you are trying to do please

    cheers

    m_n
    "Cos it's strange isn't it. You stand in the middle of a library and go 'Aaaaaaaaaaaaaaaaggggggghhhhhhh!'
    and everybody just stares at you. But you do the same in an aeroplane, and everybody joins in."
    -Tommy Cooper

  • #8
    New Coder
    Join Date
    Dec 2004
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question

    Hello

    These is what I am doing.

    I have a form with seven checkboxes & user will select any one or all of them or whatever there requirement is. After selecting checkboxes, its values will get inserted in one database field. For. e.g dbfield1 will have values A,B,C,D.

    function get_check_value (check_array)
    {
    var CHKBOX="";
    var i;
    for (i = 0; i < check_array.length; i++)
    {
    if (check_array[i].checked)
    alert("CHECKED");
    CHKBOX=CHKBOX + ',' + check_array [i].value;
    alert(CHKBOX);
    }
    check_array= CHKBOX.substring(1,CHKBOX.length);
    return check_array;
    }

    Below is the form :
    <FORM METHOD="post" NAME="MainForm" ACTION="">
    <table>
    <tr>
    <td ><input type="checkbox" name="checkbox1" value="A">A</td>
    </tr>
    <tr>
    <td ><input type="checkbox" name="checkbox1" value="B">B</td>
    </tr>
    .
    .
    .

    <tr>
    <td ><input type="checkbox" name="checkbox1" value="G">G</td>
    </tr>
    <table>
    <input type="button" class="btn" VALUE ="Save" onclick="javascript:get_check_value() ">
    </FORM>

    After getting check_array, it will be saved in dbfield1.
    I am getting only one check box value saved & not multiple.

    What's the way out?

  • #9
    Regular Coder martin_narg's Avatar
    Join Date
    Jul 2002
    Location
    Chamonix, France
    Posts
    600
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Handle this with your server-side language. Checkboxes only get posted through to the handler page if they are checked, so a simple null check for each checkbox is all that is required - building your string appropriately.

    Doing this kind of manipulation client-side has several problems with it - not least of which those users without javascript will not be supported in any way.

    I'm sure people will provide JavaScript solutions, but this should really be done server-side.

    Hope this helps.

    m_n
    "Cos it's strange isn't it. You stand in the middle of a library and go 'Aaaaaaaaaaaaaaaaggggggghhhhhhh!'
    and everybody just stares at you. But you do the same in an aeroplane, and everybody joins in."
    -Tommy Cooper

  • #10
    Regular Coder
    Join Date
    Apr 2005
    Location
    Lisbon, CT
    Posts
    339
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Perhaps you could add an alert to show what check_array contains after you assign it with the substring method. In your onclick event you pass no paramters yet the function accepts one. Is there somewhere in your code where you are assigning the check_array array to be equal to the document items. Not to be a pest about it but could you post your code for saving check_array to your database?

    BaldEagle

    [edit] I am just not quick enough. Also I missed the alert the first time.

    [edit] One last thing then I will butt out. martin_narg makes the most valid point here in that this should be done server side. However as was said, if you insist I am certain someone can help you.
    Last edited by BaldEagle; 08-13-2005 at 05:21 PM.

  • #11
    New Coder
    Join Date
    Dec 2004
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question

    Actually, I am using MVC framework of servlets, JSP. Adding data to DB is written in servlet & there is whole lot of framework(other files). Actually after getting check_array values, it should stored in DB.

  • #12
    Regular Coder martin_narg's Avatar
    Join Date
    Jul 2002
    Location
    Chamonix, France
    Posts
    600
    Thanks
    1
    Thanked 3 Times in 3 Posts
    The points in my previous post remain.

    m_n
    "Cos it's strange isn't it. You stand in the middle of a library and go 'Aaaaaaaaaaaaaaaaggggggghhhhhhh!'
    and everybody just stares at you. But you do the same in an aeroplane, and everybody joins in."
    -Tommy Cooper

  • #13
    Regular Coder
    Join Date
    Apr 2005
    Location
    Lisbon, CT
    Posts
    339
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have no experience with MVC framework, but from what I have read about it, it can be complicated at best especially when creating objects. I assume now that check_array is created by that conroller servlet. I suspect I will bow out as I don't think I can give you any help since I am not familiar with this setup. From reading many of the posts throughout these forums there are a lot of sharp people here, so it is possible that someone can give you the exact help you need.

    Good Luck,

    BaldEagle

  • #14
    New Coder
    Join Date
    Dec 2004
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up

    Thanks for feedback, problem got solved. mid() is an vbscript function & I am using javascript which uses substring method.


  •  

    Posting Permissions

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