Gathering data from form fields within iFrames

Discussion in 'Javascript' started by Jon, Jan 25, 2006.

  1. Jon

    Jon Guest

    All,

    I'm currently working with a PHP-based CMS application, and am begining to
    put the finishing touches on it via Javascript validation. Currently, I'm
    using fairly standard methods of validation of each form field, the
    algorithm is much like:

    if(document.formName.field.value == ""){
    //throw an error and return false
    }

    This works great except for one particular field. I have a javascript-based
    Rich Text Editor (RTE) that currently places the body of each page within an
    iFrame. When the page loads, I populate a field within the iFrame that is a
    textarea with data coming from the DB (MySQL). All works fine this way, and
    when the user makes a change and clicks submit, I'm able to get that data
    from the form and submit.

    The problem comes up with two things - building a preview page, and
    validating data within the field. The algorithm I'm using above will work
    within the field, however it will only give me the ORIGINAL value of the
    textarea field. If the user changes it, I'm simply unable to grab the NEW
    value of the field. As all of my other field validation works fine, I'm
    assuming this has something to do with the iFrame.

    So, can anyone give me some info on how I can grab CURRENT values of a
    textarea field within an iFrame? Currently, any changes made within the
    textarea (inside the iFrame) simply are not recognized by normal javascript
    Validation. I'm somewhat of a JS newb, but can work off any any algorithm -
    so at this point, ANY help is appreciated. Thank you in advance.
     
    Jon, Jan 25, 2006
    #1
    1. Advertising

  2. Jon

    Joe Attardi Guest

    Jon wrote:
    > if(document.formName.field.value == ""){
    > //throw an error and return false
    > }
    >
    >The algorithm I'm using above will work within the field,
    > however it will only give me the ORIGINAL value of the
    > textarea field. If the user changes it, I'm simply unable to grab the NEW
    > value of the field. As all of my other field validation works fine, I'm
    > assuming this has something to do with the iFrame.


    Jon,

    The only thing I can think of is that you are accessing the wrong
    document. An iframe has its own document object - I believe the
    property is called contentDocument, but I am not sure, so don't flame
    me if I'm incorrect. Anyway, you might want to try getting the form in
    that document object and see if that helps.

    --
    Joe Attardi
     
    Joe Attardi, Jan 25, 2006
    #2
    1. Advertising

  3. Jon

    Jon Guest

    hehe - I don't flame on newsgroups or message boards :p

    Thanks for the info - Though I was unable to build a solution exactly how I
    wanted originally, I researched what you were talking about and found a
    better way. I basically built the 'preview' functionality within the iFrame
    itself to avoid any problems of the different objects on the same page. So
    it calls the ID of the textarea from a link that sits inside the actual
    iFrame, and pushes the current value to a new window. Looks to be working
    fine now - Thanks :)

    I really need to take some Javascript classes - it's much different than
    what I'm used to (PHP/ASP) :(

    "Joe Attardi" <> wrote in message
    news:...
    > Jon wrote:
    >> if(document.formName.field.value == ""){
    >> //throw an error and return false
    >> }
    >>
    >>The algorithm I'm using above will work within the field,
    >> however it will only give me the ORIGINAL value of the
    >> textarea field. If the user changes it, I'm simply unable to grab the NEW
    >> value of the field. As all of my other field validation works fine, I'm
    >> assuming this has something to do with the iFrame.

    >
    > Jon,
    >
    > The only thing I can think of is that you are accessing the wrong
    > document. An iframe has its own document object - I believe the
    > property is called contentDocument, but I am not sure, so don't flame
    > me if I'm incorrect. Anyway, you might want to try getting the form in
    > that document object and see if that helps.
    >
    > --
    > Joe Attardi
    >
     
    Jon, Jan 25, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Xavier
    Replies:
    3
    Views:
    306
    Sean Ross
    Jul 7, 2003
  2. glowfly
    Replies:
    4
    Views:
    431
    =?UTF-8?B?QXJuZSBWYWpow7hq?=
    Sep 14, 2006
  3. Arkadiusz Miskiewicz
    Replies:
    0
    Views:
    272
    Arkadiusz Miskiewicz
    Nov 9, 2006
  4. Replies:
    1
    Views:
    378
    Victor Bazarov
    May 2, 2006
  5. Tamarin
    Replies:
    2
    Views:
    129
    Randy Webb
    Mar 6, 2007
Loading...

Share This Page