Using Javascript to get URL Parameters

There’s been a few discussions on this topic but I can’t seem to get this to work.

The following code is in the Javascript/General-Form/onLoad event of a form:
alert(<?php echo json_encode([lkreadonly]);?>);
var chkreadonly = <?php echo json_encode([lkreadonly]);?>;
alert(chkreadonly);
if (chkreadonly == “Y”) {
var frm = document.forms[‘F1’];
for(var i=0;i<frm.length;i++)
{
frm.elements[i].disabled = true;
}
}

the lkreadonly global variable is set in a calling application with the following code:
if ({payment_complete} == “1”) {
{survey} = “<a href= '” . sc_make_link(form_full_disclosure,lkidregistry={id regsitry};lkreadonly=Y) . “’ target=’_self’><button class=‘mybtn’ type=‘button’>Survey</button></a>”;
}

Now the URL for form_full_disclosure contains the correct value (in bold below) when the button is pressed:
http://127.0.0.1:8081/scriptcase/app…ryscin8scoutlkreadonlyscinYscout

This is the result when I look at the source code after the page displays:
function sc_form_onload() { alert([“lkreadonly”]); var chkreadonly = [“lkreadonly”]; alert(chkreadonly); if (chkreadonly == “Y”) { var frm = document.forms[‘F1’]; for(var i=0;i<frm.length;i++) { frm.elements[i].disabled = true; } } } When the alert pops, all I get is lkreadonly and not the Y value that was passed by the URL. My suspicion is that the timing in SC is not setting this global variable early enough so it’s correctly set when the onLoad event fires.

Any ideas on how to get the onLoad event to work correctly with a global variable?

** RESOLUTION WITH A SOLUTION ***

After doing some testing I was able to resolve this problem. Here is what I did.

In the form form_full_disclosure I put in the following code in the onScriptInit event:
?>
<script> var $lkreadonly=’<? echo [lkreadonly]; ?>’</script>
<?

In the Javascript/General-Form/onLoad event of the form:
if ($lkreadonly == “Y”) {
var frm = document.forms[‘F1’];
for(var i=0;i<frm.length;i++)
{
frm.elements[i].disabled = true;
}
}

This now correctly passes data from a global variable to a javascript variable. As a result the fields on a form are now read only when the condition is true.