It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming JavaScript Forum

Scope problem with document object

Scope problem with document object

Postby poemind on Mon Mar 26, 2007 3:40 pm

Hi, I am having a scope problem in my script.

I am tying to link 14 checkboxes together so that they must be checked in order from
top to bottom. I have done this on my local machine, but I need to put this functionality
into SugarCRM and I have ran into a snag regarding scope. I think.

Below is the text of my included file:jsinclude.js

[php]// sets up array of JavaScript id's
var sales_stages = new Array()
sales_stages[1] = "new_c";
sales_stages[2] = "notcontactedyet_c" ;
sales_stages[3] = "contacted_c";
sales_stages[4] = "decision_maker_c";
sales_stages[5] = "qualified_c";
sales_stages[6] = "demoscheduled_c";
sales_stages[7] = "democomp_c";
sales_stages[8] = "propsent_c";
sales_stages[9] = "contsent_c";
sales_stages[10] = "pendingapproval_c";
sales_stages[11] = "contractrecvd_c";
sales_stages[12] = "tobetrained_c";
sales_stages[13] = "closedlost_c";
sales_stages[14] = "mgr_review_c";

// meant to loop through checkboxes above checkbox[start_num]
function clear_up_checks( me ,ss ){

alert("inside2 clear_up_checks" + ss); //
start_num = Number(ss) ;

for( i = start_num ; i <= 14 ; i = i + 1){
document.getElementById(sales_stages[i]).checked = false;
alert(document.getElementById(sales_stages[i]));// returns [object] // (tcb) DEBUG
}
}

// takes sales stage number ss and
// returns the value of the previous
// originally 'me' referred to a passed in 'this' reference?
function is_prev_checked( me , ss ){
alert("inside4 is_prev_checked ss=" + sales_stages[ss]);
//alert(me);

chk = document.getElementById(sales_stages[ss]).checked ;
alert("2 chk = " + chk);

if( ss == "1"){
if (! document.getElementById(sales_stages[ss]).checked ){
clear_up_checks( me , ss );
}
return document.getElementById(sales_stages[ss]).checked ;
}
else if(!chk){
alert("inside !chk2");
clear_up_checks( me , ss );
alert("after calling clear_up_checks");
return false;
}
else return is_prev_checked( ss - 1 );
} [/php]

Then this is where it is referenced in the calling file:

[php]
<script language="javascript">
var myDoc = document ;
checkbox.onclick = is_prev_checked;
</script>

<td class="dataField">
<span sugar='slot4b'>

<input type='hidden' name='notcontactedyet_c' value='0'>
<input type='checkbox' name='notcontactedyet_c' id='notcontactedyet_c'
title='{NOTCONTACTEDYET_C_HELP}' value='1' onclick='is_prev_checked( myDoc ,"2");'{NOTCONTACTEDYET_C_CHECKED}>
</span sugar='slot'></td>[/php]


I am fairly certain that this a scope problem but I don't know how to resolve the issue.
How do I access the document object from thes included functions?

Thanks in advance for any help that you give me!

poemind
poemind
 
Posts: 0
Joined: Mon Mar 26, 2007 12:58 pm

Who is online

Users browsing this forum: No registered users and 3 guests