Getting user input into JavaScript

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Don W.

    Getting user input into JavaScript

    Is it possible to open a browser window from a javascript for the purpose of
    gathering user input on a form and then use data from the form in the
    javascript? How do you get the data from the form into the script?

    Don W.


  • Laurent Bugnion, GalaSoft

    #2
    Re: Getting user input into JavaScript

    Hi,

    Don W. wrote:[color=blue]
    > Is it possible to open a browser window from a javascript for the purpose of
    > gathering user input on a form and then use data from the form in the
    > javascript? How do you get the data from the form into the script?
    >
    > Don W.[/color]

    A form can be reached through different syntaxes, for example:

    document.formNa me
    document.forms[ "formName" ]
    document.forms[ index ] (not recommended)

    Once you have the Form object, you can access the elements with

    document.formNa me.elementName
    document.formNa me.elements[ "elementNam e" ]
    document.formNa me.elements[ index ]

    or other variations.

    Depending on the type of the element, you can access its value with:

    document.formNa me.elementName. value (for textfields, textareas)
    document.formNa me.elementName. checked (for checkboxes or single
    radiobuttons)
    document.formNa me.elementName[ index ].checked (for radiobutton groups)

    I recommend you to read the following for more information about this:

    <URL:
    http://devedge.netscap e.com/library/manuals/2000/javascript/1.3/reference/form.html>

    HTH,

    Laurent
    --
    Laurent Bugnion, GalaSoft
    Webdesign, Java, JavaScript: http://www.galasoft-LB.ch
    Private/Malaysia: http://mypage.bluewin.ch/lbugnion
    Support children in Calcutta: http://www.calcutta-espoir.ch

    Comment

    • Don W.

      #3
      Re: Getting user input into JavaScript

      Thank you for taking the time to provide me with all that information!

      I may not have been clear in my question. If I open a window from a script
      using something like this:
      window.open("us er_input.htm") from within a script, then how can I retrieve
      the data from a form in user_input.htm?

      The only way I can find to do this is to open a file in user_input.htm and
      write the data to the file. I still need some way for the script to know
      when to read the file.

      I don't like using this intermediate file. Do you know a better way?

      Don W.


      "Laurent Bugnion, GalaSoft" <galasoft-LB@bluewin_NO_S PAM.ch> wrote in
      message news:bm2s94$dvh $1@rex.ip-plus.net...[color=blue]
      > Hi,
      >
      > Don W. wrote:[color=green]
      > > Is it possible to open a browser window from a javascript for the[/color][/color]
      purpose of[color=blue][color=green]
      > > gathering user input on a form and then use data from the form in the
      > > javascript? How do you get the data from the form into the script?
      > >
      > > Don W.[/color]
      >
      > A form can be reached through different syntaxes, for example:
      >
      > document.formNa me
      > document.forms[ "formName" ]
      > document.forms[ index ] (not recommended)
      >
      > Once you have the Form object, you can access the elements with
      >
      > document.formNa me.elementName
      > document.formNa me.elements[ "elementNam e" ]
      > document.formNa me.elements[ index ]
      >
      > or other variations.
      >
      > Depending on the type of the element, you can access its value with:
      >
      > document.formNa me.elementName. value (for textfields, textareas)
      > document.formNa me.elementName. checked (for checkboxes or single
      > radiobuttons)
      > document.formNa me.elementName[ index ].checked (for radiobutton groups)
      >
      > I recommend you to read the following for more information about this:
      >
      > <URL:
      >[/color]
      http://devedge.netscap e.com/library/manuals/2000/javascript/1.3/reference/form.html>[color=blue]
      >
      > HTH,
      >
      > Laurent
      > --
      > Laurent Bugnion, GalaSoft
      > Webdesign, Java, JavaScript: http://www.galasoft-LB.ch
      > Private/Malaysia: http://mypage.bluewin.ch/lbugnion
      > Support children in Calcutta: http://www.calcutta-espoir.ch
      >[/color]


      Comment

      • Laurent Bugnion, GalaSoft

        #4
        Re: Getting user input into JavaScript

        Hi,

        Don W. wrote:
        [color=blue]
        > Thank you for taking the time to provide me with all that information!
        >
        > I may not have been clear in my question. If I open a window from a script
        > using something like this:
        > window.open("us er_input.htm") from within a script, then how can I retrieve
        > the data from a form in user_input.htm?
        >
        > The only way I can find to do this is to open a file in user_input.htm and
        > write the data to the file. I still need some way for the script to know
        > when to read the file.[/color]

        You couldn't do this anyway, since client-side JavaScript is not allowed
        to write files, unless in certains special security conditions, and in
        very specific (not cross-browser) ways.
        [color=blue]
        > I don't like using this intermediate file. Do you know a better way?[/color]

        You can read the data in the pop-up with:

        -------------------------------------------------
        // In the main window

        var g_wPopUp = open( ... );

        // This method is called from the pop-up when
        // the user presses the "Validate" button
        function validateForm()
        {
        var strUserName = g_wPopUp.docume nt.formName.tfU serName.value;
        // etc...
        }

        // In the pop-up:

        <INPUT TYPE="button" VALUE="validate form"
        ONCLICK="opener .validateForm() ;">

        -------------------------------------------------
        Or even better:

        // In the main window

        var g_wPopUp = open( ... );

        // This method is called from the pop-up when
        // the user presses the "Validate" button
        function validateForm( frmToValidate )
        {
        var strUserName = frmToValidate.t fUserName.value ;
        // etc...
        }

        // In the pop-up:

        <INPUT TYPE="button" VALUE="validate form"
        ONCLICK="opener .validateForm(t his.form);">

        -------------------------------------------------
        HTH,

        Laurent
        --
        Laurent Bugnion, GalaSoft
        Webdesign, Java, JavaScript: http://www.galasoft-LB.ch
        Private/Malaysia: http://mypage.bluewin.ch/lbugnion
        Support children in Calcutta: http://www.calcutta-espoir.ch

        Comment

        • Don W.

          #5
          Re: Getting user input into JavaScript

          Thank you, that's just what I was looking for!

          Don W.


          "Laurent Bugnion, GalaSoft" <galasoft-LB@bluewin_NO_S PAM.ch> wrote in
          message news:bm35so$ele $1@rex.ip-plus.net...[color=blue]
          > Hi,
          >
          > Don W. wrote:
          >[color=green]
          > > Thank you for taking the time to provide me with all that information!
          > >
          > > I may not have been clear in my question. If I open a window from a[/color][/color]
          script[color=blue][color=green]
          > > using something like this:
          > > window.open("us er_input.htm") from within a script, then how can I[/color][/color]
          retrieve[color=blue][color=green]
          > > the data from a form in user_input.htm?
          > >
          > > The only way I can find to do this is to open a file in user_input.htm[/color][/color]
          and[color=blue][color=green]
          > > write the data to the file. I still need some way for the script to[/color][/color]
          know[color=blue][color=green]
          > > when to read the file.[/color]
          >
          > You couldn't do this anyway, since client-side JavaScript is not allowed
          > to write files, unless in certains special security conditions, and in
          > very specific (not cross-browser) ways.
          >[color=green]
          > > I don't like using this intermediate file. Do you know a better way?[/color]
          >
          > You can read the data in the pop-up with:
          >
          > -------------------------------------------------
          > // In the main window
          >
          > var g_wPopUp = open( ... );
          >
          > // This method is called from the pop-up when
          > // the user presses the "Validate" button
          > function validateForm()
          > {
          > var strUserName = g_wPopUp.docume nt.formName.tfU serName.value;
          > // etc...
          > }
          >
          > // In the pop-up:
          >
          > <INPUT TYPE="button" VALUE="validate form"
          > ONCLICK="opener .validateForm() ;">
          >
          > -------------------------------------------------
          > Or even better:
          >
          > // In the main window
          >
          > var g_wPopUp = open( ... );
          >
          > // This method is called from the pop-up when
          > // the user presses the "Validate" button
          > function validateForm( frmToValidate )
          > {
          > var strUserName = frmToValidate.t fUserName.value ;
          > // etc...
          > }
          >
          > // In the pop-up:
          >
          > <INPUT TYPE="button" VALUE="validate form"
          > ONCLICK="opener .validateForm(t his.form);">
          >
          > -------------------------------------------------
          > HTH,
          >
          > Laurent
          > --
          > Laurent Bugnion, GalaSoft
          > Webdesign, Java, JavaScript: http://www.galasoft-LB.ch
          > Private/Malaysia: http://mypage.bluewin.ch/lbugnion
          > Support children in Calcutta: http://www.calcutta-espoir.ch
          >[/color]


          Comment

          Working...