Announcement

Collapse
No announcement yet.

Advice from javascript guru needed

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Advice from javascript guru needed

    Hello -

    I am hoping a kind Javascript expert can solve this little problem for me, as I do not really know JS (and I know there are some very clever people who hang out here, who are very helpful, so I thank you in advance):-

    On one of my Actinic template pages I have created an IFrame, that calls in a separate HTML page. The content of the IFrame is actually a little sign-up/survey form that the customer can fill in and Submit there and then, without being taken off the Actinic page in the store. This all works fine.

    However, what I would like to add to the form is a text input field that is automatically filled in with the title of the page the customer currently on, which will actually be the Actinic variable 'Product name'. This is what I am having a little trouble achieving.

    So, in my Actinic template for this page, between the <body></body> tags, I have the following code:-

    Code:
                
    <IFRAME id="I1" name="I1" src="http://www.....(HTML page I'm calling into the IFrame)....page.html" frameBorder=0 width=500 height=200></IFRAME>
                
    <script language="javascript" type="text/javascript">
          window.onload = function() {
          var eyeframe;
          eyeframe = document.getElementById('I1');
                                        
          var eyeframedoc;
          eyeframedoc = eyeframe.contentWindow ? eyeframe.contentWindow.document: eyeframe.contentDocument;
                
          eyeframedoc.getElementbyId('productname').value="thisWorks"; 
          }
      </script>

    Then, inside the form on the separate HTML page being called into this IFrame, I have the following input box:-

    HTML Code:
    <input type="text" id="productname" name="productname" value="startValue">
    However, when the user clicks the 'Submit' button for this form inside the IFrame, although I get all the information the user has entered into the other boxes in this form, the value for the 'productname' input box comes back as "startValue" and not "thisWorks" (which I will change to the appropriate Actinic variable when I get it working at this level).

    So the Javascript code as I have it at the moment as shown above does not seem to be having any effect in setting the value of the 'productname' text input box in the HTML page being called into the iFrame. I am not getting any 'errors', just not the effect required.

    Can anybody see where I am going wrong on this?

    Thanks again

    #2
    First, I wouldn't redefine the onload as Actinic uses this in the <body ...> tag to load some required images and set a popup flag used by the Extended Info pages.

    Instead put into your HEAD area
    Code:
    <script language="javascript" type="text/javascript">
    function setiframe() {
    	var eyeframe = document.getElementById('I1');
    	if ( eyeframe )
     		{                            
    		var eyeframedoc = eyeframe.contentWindow ? eyeframe.contentWindow.document: eyeframe.contentDocument;
          		eyeframedoc.getElementById('productname').value="thisWorks"; 
    		}
    }
    </script>
    And in your <body ...> tag change

    onload="....."

    to onload="setiframe();....."

    Now as to the problem, why not stick some alert statements in to see what's happening.

    Also test using Firefox and set it's Tools / Error console on.
    Norman - www.drillpine.biz
    Edinburgh, U K / Bitez, Turkey

    Comment


      #3
      Many thanks for the kind response.

      I have followed your advice.

      With the help of the Error Console, which I would not have known about unless you had told me, I see I am getting an error from the page the javascript code is on. The error is:-

      eyeframedoc.getElementbyID is not a function

      With the help of an alert, I know the javascript code is definitiely running, and I know the eyeframe variable is being created (alert(eyeframe.name); gave me the name of the IFrame).

      Not sure though how I can test the eyeframedoc variable is actually being created, and whether that would help me with error coming up in Error Console.

      Any further thoughts would be apprecaited!

      Comment


        #4
        Just replying to myself here.

        I worked this one out - eyeframedoc.getElementbyID is not a function, but eyeframedoc.getElementByID is!!

        And yea! everything is working as it should now.

        Thanks again Norman, I really love the NorList menu I bought from you recently.

        Best wishes & thanks again

        Comment


          #5
          Probably a typo. It should be getElementById - the capilatisation is important. I've corrected my version of your code (above) and marked the fixed "B" in red.
          Norman - www.drillpine.biz
          Edinburgh, U K / Bitez, Turkey

          Comment

          Working...
          X