Forums

Displaying User Input Elsewhere in the Form

wibadd 04 Feb, 2012
I have been given a requirement to display a disclaimer at the bottom of the form with information that user inputs at the top of the form - the organization name. I assume the only way to do this is with JS, but how do I output it in a form element so that I can include it in text. For example, I need to display the following:

The individual who accepting this Agreement has the authority to place this order on behalf of <organization>, and to commit <organization> to payment of the associated fees. In accepting this agreement, I certify that this is a binding and non-cancelable order, and that I am authorized to initiate this order on behalf of <organization>.

I have seen some posts stating that the value can be extracted from the array using $form->data['[i]fieldname[/i]']; however, the users hasn't yet submitted anything to that point.
GreyHead 04 Feb, 2012
Hi wibadd,

The only way to do this is with JavaScript - but what is supposed to display *before* the data is entered at the top of the form?

Bob
wibadd 04 Feb, 2012
Thanks for the response Bob. The disclaimer does not display until the user selects a sponsorship level, by which time they would have already inputted the organization name. So right now that header is hidden until a level is selected. Should I put all of the text into JS Load or do I keep the header text element and somehow reference the JS var to be outputted in the header text?
wibadd 04 Feb, 2012
Ok, so I finally figured out how to do this with the following JS and form code:
window.addEvent('load', function() {
  var orgname = $('legal_name');
  // execute the check after each keystroke
  orgname.addEvent('keyup', function() {
    current_value = orgname.value;
    $('disclaimer_org_name').innerHTML = current_value;
  });
});


<span id='disclaimer_org_name'>Company Legal Name</span>


There is only one problem. I need the Company Legal Name to display in 3 places in the disclaimer, but it only displays once. Is there a limit to the number of times you can display a value from JS on the form?
GreyHead 04 Feb, 2012
Hi wibadd,

The problem probably is that ids are supposed to be unique so JavaScript assumes that there is only one. You can use a class to get an array of similar elements.
<span class='disclaimer_org_name'>Company Legal Name</span>

Then $$('.disclaimer_org_name') will give you an array of these spans.

Alternatively you can use the JavaScript .replace() method to do a string replace.

Bob
This topic is locked and no more replies can be posted.