School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 300,421 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,526 people online right now. Registration is fast and FREE... Join Now!




Crazy Form error

 

Crazy Form error

Ennio

29 May, 2009 - 07:54 AM
Post #1

New D.I.C Head
*

Joined: 29 May, 2008
Posts: 22



Thanked: 1 times
My Contributions
I have a CFForm tag in my code that has a simple input box, a rich textarea, and a couple of more inputs.

But some of the iputs are generated dynamically with AJAX. For example, the user can creat a Poll so they can add as many answer as they want.

everythings works fine in Internet Explorer, but on FireFox I cannot get the dynamic content. For some reason when I submit the page it does not work and coldfusion tells me that the input is not defined.

The problem is only for the TEXTAREA.

why is that? how can i fix that?


Thanks smile.gif

This post has been edited by Ennio: 29 May, 2009 - 08:01 AM

User is offlineProfile CardPM
+Quote Post


xheartonfire43x

RE: Crazy Form Error

29 May, 2009 - 09:33 AM
Post #2

D.I.C Regular
***

Joined: 22 Dec, 2008
Posts: 260



Thanked: 2 times
My Contributions
QUOTE(Ennio @ 29 May, 2009 - 07:54 AM) *

I have a CFForm tag in my code that has a simple input box, a rich textarea, and a couple of more inputs.

But some of the iputs are generated dynamically with AJAX. For example, the user can creat a Poll so they can add as many answer as they want.

everythings works fine in Internet Explorer, but on FireFox I cannot get the dynamic content. For some reason when I submit the page it does not work and coldfusion tells me that the input is not defined.

The problem is only for the TEXTAREA.

why is that? how can i fix that?


Thanks smile.gif


We need to see some code to help you.
User is offlineProfile CardPM
+Quote Post

Ennio

RE: Crazy Form Error

29 May, 2009 - 09:47 AM
Post #3

New D.I.C Head
*

Joined: 29 May, 2008
Posts: 22



Thanked: 1 times
My Contributions
Here is the JS that I use to create the new input fields (TEXTAREA) when the user click on add poll in my FORM, also they will be able to add more answers to the poll.

CODE

// JavaScript Document

        function enablePoll(){
            document.getElementById('pollenabled').value = 'Yes';
            document.getElementById('rightContent').style.width = '';
            
        }
        function focusTitle() {
            // IE has issues with focusing the title field right away. weird, huh ?
            setTimeout('document.authorform.Title.focus()', 300);            
        }
        addToOnload(focusTitle);

        function removeAskRxCategory() {
            var control = document.getElementById("lst_Category");
            if (control) {
                for (var i = 0; i < control.options.length; i++) {
                    if (control.options[i].text.toLowerCase() == 'askrx answers'){
                        control.remove(i);
                        break;
                    }
                }
            }
        }
        addToOnload(removeAskRxCategory);
        
        function cancelAuthor() {
            
            if (confirm("Are you sure you want to cancel this poll?")) {
                window.close();
                /*document.authorform.cancel.value="true";
                SermoForms['authorform'].submit();*/
            }
        }
        
        function showPreview() {
            var oldtarget = document.authorform.target;
            var oldaction = document.authorform.action;
            var win = browserPopup('cfc_poll_preview.cfm','preview',600,500);
            win.focus();
            document.authorform.action = 'ticket/author/preview';
            document.authorform.target = 'preview';
            document.authorform.submit();
            document.authorform.target = oldtarget;
            document.authorform.action = oldaction;
        }

        function addImage() {            
            var oldtarget = document.authorform.target;
            var oldaction = document.authorform.action;
            //var newText = getHTML('edt_content_ifr');
            //setText('edt_content_ifr', newText);
            var win = browserPopup('ticket/author/uploadimage','preview',500,350);
            if (win) {
                win.focus();
            }            
            document.authorform.action = 'ticket/author/uploadimage';
            document.authorform.target = 'preview';
            document.authorform.submit();
            document.authorform.target = oldtarget;
            document.authorform.action = oldaction;
        }    

        function cancelImage() {
            document.authorform.removeImage.value = "true";
            document.authorform.submit();
        }
        
        function backStep() {
            document.authorform.step.value="Split";
            document.authorform.target = null;
            document.authorform.submit();
        }

        function toggleQuestion(idx) {

            delAllAnswers();
            setQuestionDisplay('none');

            switch(idx) {
            case 0:
                addAnswer("Yes");
                addAnswer("No, never");
                setQuestion("Have you seen this?");
                break;

            case 1:
                addAnswer("Yes");
                addAnswer("No");
                setQuestion("Do you agree?");
                break;

            case 2:
                addAnswer("");
                setQuestion("How would you explain this?");
                break;

            case 3:
                addAnswer("");
                setQuestion("");
                setQuestionDisplay('block');
                break;

            default:
                addAnswer("");
                setQuestion("");
                break;
            }

        }

        function setQuestion(qText) {

            var question = document.getElementById("edt_question");
            if (question) {
                question.innerHTML  = qText;
                question.value      = qText;
            }

        }

        function setQuestionDisplay(display) {

            var question = document.getElementById("edt_question");
            if (question) {
                question.style.display = display;
            }
        }

        function delAllAnswers() {

            var table = document.getElementById("displayedAnswers");
            if (table) {
                for (var i = (table.rows.length-1); i > 0; i--) {
                    table.deleteRow(i);
                }
            }
        }

        function delAnswer(span) {

            var table = document.getElementById("displayedAnswers");
            if (table) {

                // find the parent TR and delete
                var tr  = span.parentNode.parentNode;
                var idx = tr.rowIndex;
                table.deleteRow(idx);

                // clean up the names and IDs of remaining rows
                var tdLeft, tdRight, textarea;
                var i = idx;
                for (i; i < table.rows.length; i++) {
                    tr = table.rows[i];

                    tdLeft = tr.cells[0];
                    tdLeft.childNodes[1].innerHTML = '&nbsp;' + i + ')&nbsp';

                    tdRight         = tr.cells[1];
                    textarea        = tdRight.getElementsByTagName('textarea')[0];
                    textarea.id     = 'edt_answer_' + (i-1) + '_content';
                    textarea.name   = 'answer_' + (i-1) + '_content';

                }
            }

        }

        function addAnswer(ans) {

            var table = document.getElementById("displayedAnswers");
            if (table) {

                var tr      = table.insertRow(-1);
                var tdLeft  = tr.insertCell(-1);
                var tdRight = tr.insertCell(-1);

                tdLeft.className    = 'qAnswerIdx';
                tdLeft.innerHTML    = '<img id=\"img_delAnswer\" onclick="delAnswer(this)" class="delAnswer" src="http://cfcenters.com/members/ui/images/polls/deletewhite-o.png" width="9" height="11" alt="Delete" title="Delete this answer" /><span>&nbsp;' + tr.rowIndex + ')&nbsp;</span>';

                tdRight.style.verticalAlign = 'top';

                var textarea = document.createElement('textarea');
                textarea.style.width    = '200px';
                textarea.style.height   = '5em';
                textarea.id             = 'edt_answer_' + (tr.rowIndex-1) + '_content';
                textarea.name           = 'answer_' + (tr.rowIndex-1) + '_content';
                textarea.maxlength      = '1000';
                textarea.innerHTML      = ans;
                textarea.onblur = new Function("textAreaValidate(this, 1000)");
                textarea.onkeyup = new Function("textAreaValidate(this, 1000)");
                tdRight.appendChild(textarea);
                textarea.focus();
            }

        }
        
        function trim(str)
        {
            s=str.replace(/^(\s)*/,"");
            s=s.replace(/(\s)*$/,"");
            return s;
        }
  function showNext() {
            // ensure all answers have a value
            var i = 0;
            var trimmed;
            
            var question = document.getElementById('edt_question');
            var type = document.getElementById("rad_pType2");

                if(trim(question.value).length < 1){
                    toggleError("questionError","block");
                    return(false);
                }
                else{
                    toggleError("questionError",'none');
                    var textarea = document.getElementById('edt_answer_' + i + '_content');
                    while(textarea != null) {                    
                        trimmed = trim(textarea.value);
                        if (trimmed.length < 1) {
                            toggleError("answerError","block");
                            return(false);
                        }                  
                        i++;
                        textarea = document.getElementById('edt_answer_' + i + '_content');
                    }
                    toggleError("answerError","none");
                }
        
             document.authorform.submit();
            /*SermoForms['authorform'].submit();*/
        }

        

    
        function toggleError(element, display){
            var ele = document.getElementById(element);
            if(ele != null){
                ele.style.display = display
            }
        }


        function toggleSurvey(idx) {
            var toggledDiv = document.getElementById("questionsAndAnswers");
            var reminderDiv = document.getElementById("surveyOnReminder");
            switch(idx) {
            case 0:                
                if (toggledDiv) {
                        toggledDiv.style.display = 'block';
                        reminderDiv.style.display = 'none';
                        
                        var previewButton = document.getElementById("btn_Preview");
                        
                        previewButton.disabled = false;
                       juggleClass(previewButton, "disabled", 0);
                  }
                break;                
            case 1:
                if (toggledDiv) {
                        toggledDiv.style.display = 'none';
                        reminderDiv.style.display = 'block';
                        
                        var previewButton = document.getElementById("btn_Preview");
                        previewButton.disabled = true;
                       juggleClass(previewButton, "disabled", 1);                        
                  }                
                break;
            }
        
        }
    // -->



This code works perfect in IE, but not on FireFox
User is offlineProfile CardPM
+Quote Post

xheartonfire43x

RE: Crazy Form Error

1 Jun, 2009 - 05:26 AM
Post #4

D.I.C Regular
***

Joined: 22 Dec, 2008
Posts: 260



Thanked: 2 times
My Contributions
QUOTE(Ennio @ 29 May, 2009 - 09:47 AM) *

Here is the JS that I use to create the new input fields (TEXTAREA) when the user click on add poll in my FORM, also they will be able to add more answers to the poll.

This code works perfect in IE, but not on FireFox


This is the coldfusion forum... not Javascript.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/8/09 12:10AM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month