...

View Full Version : object expected error?



pashah72
08-13-2005, 12:50 PM
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?

vwphillips
08-13-2005, 01:16 PM
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

martin_narg
08-13-2005, 01:16 PM
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

pashah72
08-13-2005, 01:36 PM
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

vwphillips
08-13-2005, 01:57 PM
Edit: Sorry vwphillips - we posted at the same time

happens all the time but seldom exactly the same time

BaldEagle
08-13-2005, 01:59 PM
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.

martin_narg
08-13-2005, 02:13 PM
Pasha72 - could you explain what you are trying to do please

cheers

m_n

pashah72
08-13-2005, 03:49 PM
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?

martin_narg
08-13-2005, 04:14 PM
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

BaldEagle
08-13-2005, 04:14 PM
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.

pashah72
08-13-2005, 04:24 PM
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.

martin_narg
08-13-2005, 04:40 PM
The points in my previous post remain.

m_n

BaldEagle
08-13-2005, 04:42 PM
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

pashah72
08-18-2005, 09:17 AM
Thanks for feedback, problem got solved. mid() is an vbscript function & I am using javascript which uses substring method.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum