retrieving information from form

Discussion in 'Javascript' started by 4Ankit@gmail.com, Mar 24, 2007.

  1. Guest

    hello all, i am having some difficulty retrieving information from my
    form. I want to add content in my table but the content i want to add
    to the table is what the user inputs in my form.

    Basically i want to know how i retrieve information from the form so i
    can disaply it in the table.

    i have put the code i am using below, the feature i cannot get to work
    is the change content function. I want the email address entered by
    the user,if the change content button is clicked it copies the email
    address in the the top of the table.

    Below is the code i am using:

    <html>
    <head>
    <title>retrieve information from form </title>

    <script type="text/javascript">


    function changeContent()
    {
    var x=document.getElementById('myTable').rows[0].cells
    x[1].innerHTML=document.getElementById('test.emailaddress')
    }
    </script>


    <style type="text/css">
    strong {font-weight:bolder;
    color: powder blue;
    font-style:Minion;
    font-size:50%};
    </style>
    <head>

    <body>
    <h1> Worldcup Groups <h1>

    <table id="myTable" border="1">


    <tr>


    <td>Game1</td>


    <td>India</td>


    </tr>


    <tr>


    <td>Game2</td>


    <td>Pakistan</td>


    </tr>


    <tr>


    <td>Game3</td>


    <td>Sri Lanka</td>


    </tr>


    </table>

    <formname = "test">
    <p>
    <label>Email Address:
    <input type = "text"value="e.g. " name =
    "emailaddress" size = "35" maxlength=
    "35"/>
    </label>
    </P>

    <input type="button" onclick="changeContent()" value="Change content">
    </form>
    </body>
    </html>
     
    , Mar 24, 2007
    #1
    1. Advertising

  2. shimmyshack Guest

    On 24 Mar, 13:00, wrote:
    > hello all, i am having some difficulty retrieving information from my
    > form. I want to add content in my table but the content i want to add
    > to the table is what the user inputs in my form.
    >
    > Basically i want to know how i retrieve information from the form so i
    > can disaply it in the table.
    >
    > i have put the code i am using below, the feature i cannot get to work
    > is the change content function. I want the email address entered by
    > the user,if the change content button is clicked it copies the email
    > address in the the top of the table.
    >
    > Below is the code i am using:
    >
    > <html>
    > <head>
    > <title>retrieve information from form </title>
    >
    > <script type="text/javascript">
    >
    > function changeContent()
    > {
    > var x=document.getElementById('myTable').rows[0].cells
    > x[1].innerHTML=document.getElementById('test.emailaddress')}
    >
    > </script>
    >
    > <style type="text/css">
    > strong {font-weight:bolder;
    > color: powder blue;
    > font-style:Minion;
    > font-size:50%};
    > </style>
    > <head>
    >
    > <body>
    > <h1> Worldcup Groups <h1>
    >
    > <table id="myTable" border="1">
    >
    > <tr>
    >
    > <td>Game1</td>
    >
    > <td>India</td>
    >
    > </tr>
    >
    > <tr>
    >
    > <td>Game2</td>
    >
    > <td>Pakistan</td>
    >
    > </tr>
    >
    > <tr>
    >
    > <td>Game3</td>
    >
    > <td>Sri Lanka</td>
    >
    > </tr>
    >
    > </table>
    >
    > <formname = "test">
    > <p>
    > <label>Email Address:
    > <input type = "text"value="e.g. " name =
    > "emailaddress" size = "35" maxlength=
    > "35"/>
    > </label>
    > </P>
    >
    > <input type="button" onclick="changeContent()" value="Change content">
    > </form>
    > </body>
    > </html>


    what do you want to do this for? any changes made in this way, or
    email addresses entered will be lost once the page is refreshed.
    In order to save the data entered you need to use a server side
    scripting language like php/python/ruby/perl etc... to save those
    changes.

    The thing you are doing at the moment, can be done using (although
    there's no finesse and there are better ways)

    <script type="text/javascript">
    function changeContent()
    {
    var input = document.getElementById('enter_email');
    var p = document.getElementById('email');

    //add the email into the paragraph
    p.innerHTML = input.value;

    //if you just want to blank the input afterwards
    // input.value = '';
    }
    </script>
    <p id="email"></p>
    <input type="text" id="enter_email" size="35" />
    <input type="button" onclick="changeContent();" />
     
    shimmyshack, Mar 24, 2007
    #2
    1. Advertising

  3. ASM Guest

    a écrit :
    > hello all, i am having some difficulty retrieving information from my
    > form. I want to add content in my table but the content i want to add
    > to the table is what the user inputs in my form.
    >
    > Basically i want to know how i retrieve information from the form so i
    > can disaply it in the table.


    var myData = document.myForm.myInput.value;

    with :
    myForm = name of your form (not the id !)
    myInput = name of your text field (not the id !)

    > i have put the code i am using below, the feature i cannot get to work
    > is the change content function. I want the email address entered by
    > the user,if the change content button is clicked it copies the email
    > address in the the top of the table.
    >
    > Below is the code i am using:
    >
    > <html>
    > <head>
    > <title>retrieve information from form </title>
    >
    > <script type="text/javascript">
    >
    >
    > function changeContent()
    > {
    > var x=document.getElementById('myTable').rows[0].cells
    > x[1].innerHTML=document.getElementById('test.emailaddress')


    That (getElementById) will not work with firefox because your form and
    elements have not an id.
    That will not work because you don't call the "value" of the field.

    x[1].innerHTML = document.test.emailaddress.value;

    x[1].innerHTML = document.forms['test'].elements['emailaddress'].value;

    x[1].innerHTML = document.forms[0][0].value;

    > }
    > </script>



    > <table id="myTable" border="1">
    >
    >
    > <tr>



    Take care of spaces in your code !

    > <formname = "test">


    <form name="test">

    > <p>
    > <label>Email Address:
    > <input type = "text"value="e.g. " name =
    > "emailaddress" size = "35" maxlength=
    > "35"/>


    <input type="text" value="e.g. "
    name="emailaddress" size="35" maxlength="35"/>

    > </label>
    > </P>
    >
    > <input type="button" onclick="changeContent()" value="Change content">


    and why not :

    <input type="button" onclick="changeContent()" value="Change content" />

    > </form>
    > </body>
    > </html>



    --
    Stephane Moriaux et son (moins) vieux Mac déjà dépassé
    Stephane Moriaux and his (less) old Mac already out of date
     
    ASM, Mar 24, 2007
    #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. Rob
    Replies:
    2
    Views:
    4,443
  2. Boban Dragojlovic
    Replies:
    2
    Views:
    513
    Patrice
    Apr 19, 2004
  3. =?Utf-8?B?SWFuIFdpbGxpYW1zb24=?=

    Retrieving state information from a middle tier

    =?Utf-8?B?SWFuIFdpbGxpYW1zb24=?=, Feb 25, 2005, in forum: ASP .Net
    Replies:
    6
    Views:
    1,282
    =?Utf-8?B?aW5ldG11Zw==?=
    Feb 25, 2005
  4. =?Utf-8?B?ZG90bmV0dGVzdGVy?=

    Retrieving mailbox information through ADSI

    =?Utf-8?B?ZG90bmV0dGVzdGVy?=, Aug 31, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    449
    =?Utf-8?B?ZG90bmV0dGVzdGVy?=
    Aug 31, 2005
  5. =?Utf-8?B?Sm9l?=

    Re: Retrieving Image information

    =?Utf-8?B?Sm9l?=, Sep 20, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    439
    Bruce Barker
    Sep 21, 2005
Loading...

Share This Page