You are viewing limited content. For full access, please sign in.

Question

Question

How can I change the unique ID# of Form fields?

asked on August 28, 2015

If you open the CSS and Javascript pane on the Forms editor, you will see each field or HTML block has an id# referenced as id=q1, id=q#2 etc

It appears that once these are created, they are unique forever on a given form even if you delete a field that uses that number. No future field will ever use that same number on this form.

I have a block of javascript that I am dropping in to multiple Forms, and to make it stay consistent, I am dropping it in as a .getScript call in the Javascript pane. That way I can make future updates to the javascript and have that update on all Forms it references.

This javascript references specific field ID#s. The same 4 fields will be on every Form I drop this in to. I need to go back to previous Forms that have id#s and use the id#s that my script references.

Is there a way outside of the GUI interface to go and change the id#s of certain fields on the Form? Obviously I need to ensure no other active field uses the same id# before changing a field to that id#.

Thank you!

0 0

Replies

replied on August 28, 2015

Is there a reason why you are referencing by id instead of class? If your js uses the class name, you just need to update the fields in your form with it.

0 0
replied on August 28, 2015 Show version history

I thought the same thing, but the developer writing the script tells me that he can't reference it by class, only id# for some programmatic reason. For what it's worth, I replaced his calls by id# with classes I placed behind the fields in question, and the script stopped working. 

So what we're really trying to do, is if the value of a particular field is "True" (based on something returned back from a stored procedure) we want to go ahead and change the attributes on some fields to read only. I know I can do that normally through something like

   $('#Field59').attr('readonly', 'true');

I can probably even replace #Field59 with .classname if I put that as the class name behind that field.

Problem is I can't get the trigger to work when using classes - just field ID #s. What is a script I could use, that only references fields by their class, that will cause another field to go read only on a "change" event in another field?

I still think it'd be nice if there's some way I can change ID#s, for future reference.

More complete code snippet as it works today:

var $Field86 = $('#Field86');
$Field86.change(function () {
    if (this.value != 'True') {
        window.location.assign("http://someplacewereredirectingthem.com");
    } else {   
        $('#Field59').attr('readonly', 'true');
        $('#Field86').attr('readonly', 'true');
        $('#Field88').attr('readonly', 'true');
        $('#Field63').attr('readonly', 'true');
    }

});

So basically we're running a lookup that loads on Form load due to some parameters passed in through the URL. Those parameters trigger a SQL lookup. If the word "True" comes back from the SQL stored procedure, we set those field values to read only. Otherwise, we redirect to another website. Make sense? I just need to set it up so that instead of using field IDs, it uses classes. But I can't get that to work.

0 0
replied on August 28, 2015

What sort of fields are you trying to make read-only? Are these just standard HTML input fields (like a single line field in the form)? If they are input fields, you'd need to specify that in the javascript. For example, give the fields the class name, ro. Then use this javascript

$('.ro input').attr('readonly', true);
0 0
replied on August 30, 2015

I don't know if that's what you're looking for, but I have used the following type of command to change the ID of an elements in a Form:

$('#q1').attr('id', 'my_id');

It was useful to me when dealing with collections, which repeat the IDs of the various fields.

Hope it helps!

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.