This is a migrated thread and some comments may be shown as answers.

Modifying form input attributes

2 Answers 82 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Roger Withnell
Top achievements
Rank 1
Roger Withnell asked on 18 Jun 2010, 11:43 AM
Having built a form with several inputs and a submit button, how do I set the input name attribute?

I have the following javascript:

             var editor = $find("<%=RadEditor1.ClientID %>");  
             var jDocument = editor.get_document();  
             var jInputElements = jDocument.getElementsByTagName("input");  
                 var jCtr = 0;  
                 for (var i = 0; i < jInputElements.length; i++) {  
                     if (jInputElements[i].type != 'submit') {  
                         alert(jInputElements[i].type);  
                         jInputElements[i].name = jInputElements[i].type + jCtr;  
                     }  
                     jCtr += 1;  
                 }  
 

I get get the type successfully, but the code does not set the name.

Your help would be much appreciated.

Thanking you in anticipation.

Roger

2 Answers, 1 is accepted

Sort by
0
Roger Withnell
Top achievements
Rank 1
answered on 18 Jun 2010, 03:54 PM
I think I have fixed this problem  by replacing:

jInputElements[i].name = jInputElements[i].type + jCtr;

with:

jInputElements[i].setAttribute(

'name', jInputElements[i].type + jCtr);

 


but I appear to have a related problem.

This javascript function is called with OnClientClick in the Save button when the RTE content is saved.

If the RTE content is in Design view when the Save button is clicked, the name values are set to the input tags correctly.

But if the RTE is in Html view when the Save button is clicked, the name values are not saved, even though the funtions runs and the content is saved without errors.

Furthermore, if I make other changes in the content area in Design view and then switch to Html view before saving, on click Save, the other changes are saved but the name values are not saved.

Please advise.

Roger

0
Rumen
Telerik team
answered on 21 Jun 2010, 09:37 AM
Hi Roger,

If the editor is set in HTML mode then make a check and set it in Design mode before submitting the content, e.g.

<script type="text/javascript">
    function OnClientSubmit(editor, args) {
        if (editor.get_mode() == 2) editor.set_mode(1);
        
        }
        alert(editor.get_html(true));
         }
</script>

<telerik:RadEditor id="RadEditor1" runat="server" OnClientSubmit="OnClientSubmit"></telerik:RadEditor>

Greetings,
Rumen
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Editor
Asked by
Roger Withnell
Top achievements
Rank 1
Answers by
Roger Withnell
Top achievements
Rank 1
Rumen
Telerik team
Share this question
or