I am trying to pass a variable from the URL and populate an input field in a modal form. The modal form is only being used to enter new records. I am calling the form from a button that is wrapped in a hyperlink that looks like this:
Clicking the button successfully loads the modal form. However, I am having trouble populating a field in the modal form with the variable from the URL. I have a Load JS event (I have tried setting the Dynamic File option to both yes and no) in the form that parses the URL, gets the variable and tries to pass it to the appropriate field in the form. The code looks like this:
This gets as far as my alert box which correctly shows the variable I am passing (I have only included the alert box for debugging purposes). I could be wrong, but it looks like the modal form is not completely loaded before the Javascript finishes so the input field never gets populated. How can I solve this? Am I going about this the wrong way? Any help is greatly appreciated.
Thanks,
John
<a class="modal" href="index.php?option=com_chronoforms&tmpl=component&chronoform=AirframeStatusDetails2Add&tailnumber=<?php echo $tailno; ?>" rel="{handler: 'iframe', size: {x: 350, y: 580}}"><input style="background-color:#E0E0E0; width:65px !important; margin-right:25px;" class="btn btn-small" type="button" value="New"></a>
Clicking the button successfully loads the modal form. However, I am having trouble populating a field in the modal form with the variable from the URL. I have a Load JS event (I have tried setting the Dynamic File option to both yes and no) in the form that parses the URL, gets the variable and tries to pass it to the appropriate field in the form. The code looks like this:
function getQueryParams(qs) {
qs = qs.split("+").join(" ");
var params = {}, tokens,
re = /[?&]?([^=]+)=([^&]*)/g;
while (tokens = re.exec(qs)) {
params[decodeURIComponent(tokens[1])] = decodeURIComponent(tokens[2]);
}
return params;
}
var query = getQueryParams(document.location.search);
alert(query.tailnumber);
document.getElementById('inputtailnumber').value=query.tailnumber;
This gets as far as my alert box which correctly shows the variable I am passing (I have only included the alert box for debugging purposes). I could be wrong, but it looks like the modal form is not completely loaded before the Javascript finishes so the input field never gets populated. How can I solve this? Am I going about this the wrong way? Any help is greatly appreciated.
Thanks,
John
Hi John,
Change the name of the input* to tailnumber and remove the JavaScript and ChronoForms should automatically populate the input.
Bob
* or change the url to match the name of the input.
Change the name of the input* to tailnumber and remove the JavaScript and ChronoForms should automatically populate the input.
Bob
* or change the url to match the name of the input.
I thought I tried that first. So, should I change it to the name of the input with or without the Model ID? If it needs the Model ID what syntax do I use in the URL? (STDTL.input_tail_number, STDTL[input_tail_number], or something else?) As always, I very much appreciate your quick response!
Thanks,
John
Thanks,
John
This topic is locked and no more replies can be posted.