I'm having trouble implementing a js function. My skills are limmited... I don't have access to field ID's because the fields are widgets and no ID's are listed so I am forced to use field names.
There is a default value for an email address field allowing customers to send in anonymous emails through the webbform. The thing is, I would like to have a text shown when this default email address is not changed (this as there would be no way to answer the email)
<rn:widget path="input/FormInput" name="Contact.Emails.PRIMARY.Address" required="false" label_input="E-postadress" default_value="[email protected]" />
As the above makes the email by default [email protected] I would need to call a function when an event happens. I thought I could just check for a change on the subject field and show a message when the email address is still equal to [email protected]
I thought the following code would solve my problem but it doesn't seem to register the change event. Any advice on what I did wrong?
<rn:widget path="input/FormInput" name="Contact.Emails.PRIMARY.Address" required="false" label_input="E-postadress" default_value="[email protected]" />
<p id="Message"></p>
<rn:widget path="input/FormInput" name="Incident.Subject" required="true" label_input="Subject" />
<script>
document.getElementsByTagName('Incident.Subject')[0].onchange = function() {
var x = document.getElementsByName("Contact.Emails.PRIMARY.Address")[0].value;
if (x == '[email protected]') {
document.getElementById("Message").innerHTML = 'Some text...';
}
}
</script>
Edit: I had a bright idea this morning, I thought let's check the source code when the html is rendered and I found the ID's there :-) So I guess this means there are alternative solutions now, using ID's.
<input type="email" id="rn_TextInput_4_Contact.Emails.PRIMARY.Address" name="Contact.Emails.PRIMARY.Address" class="rn_Email" maxlength='80' value='[email protected]' />
<input type="text" id="rn_TextInput_11_Incident.Subject" name="Incident.Subject" class="rn_Text" maxlength='240' required />
Use event listener.