How to pass value from a text in a page to a table in another page

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • elham477
    New Member
    • May 2010
    • 22

    #1

    How to pass value from a text in a page to a table in another page

    I have two pages. The first page contain a table with title and the second contain texts & selected option.
    I want it so when a user in second page clicks the submit button, his information is inserted in the table in the first page according the title in table.

    How would i do this?
    ............... .
    here is my first page code:
    Code:
    <html>
    <head>
    <script type="text/javascript">
    function open_win() 
    {
    window.open("\add.html");
    }
    </script>
    </head>
    
    <body>
    <p align="center"><big>WellCome</big></p>
    <iframe id="myframe" src="" width="400" height="300" name="iframe">
    </iframe>
    <script type="text/javascript">
    document.getElementById("myframe").align="center"
    </script>
    <br>
    <br>
    <br>
    <form name="f1" method="post">
    <table width="100%">
     <tr >
      <td >
       Reading English<br />
       <table class="menu" id="tutorials" width="120" name="read">
       <tr><td class="menu"><a href="http://www.writingenglish.com" target="iframe">ReadPart01</a></td></tr>
       <tr><td class="menu"><a href="http://www.writingenglish.comp" target="iframe">ReadPart02</a></td></tr>
       <tr><td class="menu"><a href="http://www.writingenglish.com" target="iframe">ReadPart03</a></td></tr>
       <tr><td class="menu"><a href="http://www.writingenglish.com" target="iframe">ReadPart04</a></td></tr>
       <tr><td class="menu"><a href="http://www.writingenglish.com" target="iframe">ReadPart05</a></td></tr>
       </table>
      </td>
    <td >
       Listening English<br />
       <table class="menu" id="tutorial" width="120">
       <tr><td class="menu"><a href="http://www.englishlistening.com/" target="iframe">ListenPart01</a></td></tr>
       <tr><td class="menu"><a href="http://www.englishlistening.com/" target="iframe">ListenPart02</a></td></tr>
       <tr><td class="menu"><a href="http://www.englishlistening.com/" target="iframe">ListenPart03</a></td></tr>
       <tr><td class="menu"><a href="http://www.englishlistening.com/" target="iframe">ListenPart04</a></td></tr>
       <tr><td class="menu"><a href="http://www.englishlistening.com/" target="iframe">ListenPart05</a></td></tr>
       </table>
      </td>
      <td >
       Writing English<br />
       <table class="menu" id="scripting" width="120">
       <tr><td class="menu"><a href="http://www.talkenglish.com/" target="iframe">WritePart01</a></td></tr>
       <tr><td class="menu"><a href="http://www.talkenglish.com/" target="iframe">WritePart02</a></td></tr>
       <tr><td class="menu"><a href="http://www.talkenglish.com/" target="iframe">WritePart03</a></td></tr>
       <tr><td class="menu"><a href="http://www.talkenglish.com/" target="iframe">WritePart04</a></td></tr>
       <tr><td class="menu"><a href="http://www.talkenglish.com/" target="iframe">WritePart05</a></td></tr>
       </table>
      </td>
      <td >
       Speaking English<br />
       <table class="menu" id="validation" width="120">
       <tr><td class="menu"><a href="http://www.englishclub.com/reading/short-stories.htm" target="iframe">SpeakPart01</a></td></tr>
       <tr><td class="menu"><a href="http://www.englishclub.com/reading/short-stories.htm" target="iframe">SpeakPart02</a></td></tr>
       <tr><td class="menu"><a href="http://www.englishclub.com/reading/short-stories.htm" target="iframe">SpeakPart03</a></td></tr>
       <tr><td class="menu"><a href="http://www.englishclub.com/reading/short-stories.htm" target="iframe">SpeakPart04</a></td></tr>
       <tr><td class="menu"><a href="http://www.englishclub.com/reading/short-stories.htm" target="iframe">SpeakPart05</a></td></tr>
       </table>
      </td>
     </tr>
    </table>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <input type=button value="Add New Address" onclick="open_win()">
    </form>
    </body>
    </html>
    ............... ............... ............... ........
    here is my second page source:
    Code:
    <html>
    <head>
    <script type="text/javascript">
    function formSubmit()
    {
    document.getElementById("frm1").submit();
    }
    function passmain(){
     if (document.getElementByname('cat').value =="1") { 
    
     var cell_obj = window.opener.document.getElementById('tutorials').insertRow().insertCell()
     cell_obj.innerHTML= document.getElementById('txt2').value 
    }
     else 
    if (document.getElementByname('cat').value =="2") { 
    
     var cell_obj = window.opener.document.getElementById('tutorial').insertRow().insertCell()
     cell_obj.innerHTML= document.getElementById('txt2').value 
    }
    else
    
    if (document.getElementByname('cat').value =="3") { 
    
     var cell_obj = window.opener.document.getElementById('validation').insertRow().insertCell()
     cell_obj.innerHTML= document.getElementById('txt2').value 
    }
    else
    if (document.getElementByname('cat').value =="4") { 
    
     var cell_obj = window.opener.document.getElementById('scripting').insertRow().insertCell()
     cell_obj.innerHTML= document.getElementById('txt2').value 
    }
    }
    }
    
    </script>
    </head>
    
    <body onbeforeunload="passmain()">
    <p> You can Add your Address Here :</p>
    
    <form id="frm1"  method="get" action="demo.htm">
    write the address : <input  name="txtadd" type="text" id="txt1"> <br>
    write a name for it! : <input name="txtcat" type="text" id="txt2"> <br>
    choose your category: <select name="cat">
    <option value="1">ReadingEnglish </option>
    <option value="2"> ListeningEnglish </option>
    <option value="3"> WritingEnglish </option>
    <option value="4"> SpeakingEnglish </option>
    </select>
    <br>
    <br>
    <input name="btn1" type="button" onclick="passmain()" value="Click to Add it ! " ><br>
    </form>
    </body>
    </html>
    Last edited by Niheel; May 19 '10, 07:14 PM. Reason: added code tags, fixed grammar, punctuation and spelling
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5390

    #2
    from the child window that you opened you might refer to the parent window with:
    Code:
    window.opener
    you might have a look here for its usage ...

    kind regards

    Comment

    • elham477
      New Member
      • May 2010
      • 22

      #3
      Originally posted by gits
      from the child window that you opened you might refer to the parent window with:
      Code:
      window.opener
      you might have a look here for its usage ...

      kind regards
      Thank you for the answer, but I used this method in my child code on line 11. It does not work.
      I want to insert it in the table.
      Last edited by Niheel; May 19 '10, 07:15 PM. Reason: spelling, grammar, punctuation

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5390

        #4
        then your question is not how to pass a value between different windows but how to add a row to a table ... and how to correctly retrieve values from form-elements

        the script has some issues ->

        first:
        Code:
        document.getElementByname('cat'),value
        doesn't exist ... it should be:
        Code:
        document.getElementsByName('cat')[0].value
        second:

        there is a curly brace that breaks the syntax in line 34 ... in case you would use a better indentation you would see that quite easily .... and it would be better to use a variable instead of retrieving the value in every condition again ... you might even consider a switch statement in such cases.

        regards

        Comment

        • elham477
          New Member
          • May 2010
          • 22

          #5
          Originally posted by gits
          then your question is not how to pass a value between different windows but how to add a row to a table ... and how to correctly retrieve values from form-elements

          the script has some issues ->

          first:
          Code:
          document.getElementByname('cat'),value
          doesn't exist ... it should be:
          Code:
          document.getElementsByName('cat')[0].value
          second:

          there is a curly brace that breaks the syntax in line 34 ... in case you would use a better indentation you would see that quite easily .... and it would be better to use a variable instead of retrieving the value in every condition again ... you might even consider a switch statement in such cases.

          regards
          my question is: how to pass a text value between different windows and insert this text in a table in another page.
          according to the cat (category) in my first page , i want to insert this text into that table !!!

          Comment

          • gits
            Recognized Expert Moderator Expert
            • May 2007
            • 5390

            #6
            did you fix the errors i showed you in post #4? ... that errors are obvious ...

            Comment

            • elham477
              New Member
              • May 2010
              • 22

              #7
              Originally posted by gits
              did you fix the errors i showed you in post #4? ... that errors are obvious ...
              thanks dear for replying
              yes i fixed it ! but still show the first page without any change.
              when i fill the text in second page i want to show them in first page in a table.!!!

              Comment

              • gits
                Recognized Expert Moderator Expert
                • May 2007
                • 5390

                #8
                please repost your changed code again ... so that we might have a closer look at it again ...

                kind regards

                Comment

                • elham477
                  New Member
                  • May 2010
                  • 22

                  #9
                  Originally posted by gits
                  please repost your changed code again ... so that we might have a closer look at it again ...

                  kind regards
                  this the second page code, the first page is the same:
                  Code:
                  <html>
                  <head>
                  <script type="text/javascript">
                  function formSubmit()
                  {
                  document.getElementById('frm1').submit();
                  }
                  function passmain(){
                   if (document.getElementsByName('cat')[1].value=="ReadingEnglish") { 
                  
                   var cell_obj = window.opener.document.getElementById('tutorials').insertRow().insertCell()
                   cell_obj.innerHTML= document.getElementById('txt2').value 
                  }
                   else 
                  if (document.getElementsByName('cat')[1].value=="ListeningEnglish") { 
                  
                   var cell_obj = window.opener.document.getElementById('tutorial').insertRow().insertCell()
                   cell_obj.innerHTML= document.getElementById('txt2').value 
                  }
                  else
                  
                  if (document.getElementsByName('cat')[1].value=="WritingEnglish") { 
                  
                   var cell_obj = window.opener.document.getElementById('validation').insertRow().insertCell()
                   cell_obj.innerHTML= document.getElementById('txt2').value 
                  }
                  else
                  if (document.getElementsByName('cat')[1].value=="SpeakingEnglish") { 
                  
                   var cell_obj = window.opener.document.getElementById('scripting').insertRow().insertCell()
                   cell_obj.innerHTML= document.getElementById('txt2').value 
                  }
                  }
                  }
                  
                  </script>
                  </head>
                  
                  <body onbeforeunload="passmain()">
                  <p> You can Add your Address Here :</p>
                  
                  <form id="frm1"  method="get" action="demo.htm">
                  write the address : <input  name="txtadd" type="text" id="txt1"> <br>
                  write a name for it! : <input name="txtcat" type="text" id="txt2"> <br>
                  choose your category: <select name="cat">
                  <option value="1">ReadingEnglish </option>
                  <option value="2"> ListeningEnglish </option>
                  <option value="3"> WritingEnglish </option>
                  <option value="4"> SpeakingEnglish </option>
                  </select>
                  <br>
                  <br>
                  <input name="btn1" type="submit" onclick="formSubmit()" value="Click to Add it ! " ><br>
                  </form>
                  </body>
                  </html>
                  Last edited by gits; May 9 '10, 09:20 AM. Reason: added code tags

                  Comment

                  • gits
                    Recognized Expert Moderator Expert
                    • May 2007
                    • 5390

                    #10
                    there are more issues - i give you a new start to recode your script:

                    Code:
                    <html>
                    <head>
                    <script type="text/javascript">
                    
                    function formSubmit() {
                        document.getElementById('frm1').submit();
                    }
                    
                    function passmain() {
                        var val = document.getElementsByName('cat')[0].value;
                        
                        switch (val) {
                        case '1':
                            break;
                        case '2':
                            break;
                        }
                        
                        formSubmit();
                    }
                     
                    </script>
                    </head>
                     
                    <body>
                        <p> You can Add your Address Here :</p>
                     
                        <form id="frm1"  method="get" action="demo.htm">
                            write the address : <input  name="txtadd" type="text" id="txt1"> <br>
                            write a name for it! : <input name="txtcat" type="text" id="txt2"> <br>
                            choose your category: 
                            <select name="cat">
                                <option value="1">ReadingEnglish </option>
                                <option value="2"> ListeningEnglish </option>
                                <option value="3"> WritingEnglish </option>
                                <option value="4"> SpeakingEnglish </option>
                            </select>
                            <br>
                            <br>
                            <input name="btn1" type="button" onclick="passmain();" value="Click to Add it ! " ><br>
                        </form>
                    </body>
                    </html>
                    first:

                    document.getEle mentsByName('ca t') returns a node list ... and JavaScript always starts counting at 0 not 1 so in your code the value isn't retrieved

                    second:

                    the value isn't the option's text but its value ... so your conditions would never match ... you need to check for the value

                    third:

                    you didn't fix the curly brace issue either ... so basically the first error that occurs is a syntax error -> so use the shown switch statement and a clean indentation to avoid such simple errors ...

                    regards

                    Comment

                    • elham477
                      New Member
                      • May 2010
                      • 22

                      #11
                      Originally posted by gits
                      there are more issues - i give you a new start to recode your script:

                      Code:
                      <html>
                      <head>
                      <script type="text/javascript">
                      
                      function formSubmit() {
                          document.getElementById('frm1').submit();
                      }
                      
                      function passmain() {
                          var val = document.getElementsByName('cat')[0].value;
                          
                          switch (val) {
                          case '1':
                              break;
                          case '2':
                              break;
                          }
                          
                          formSubmit();
                      }
                       
                      </script>
                      </head>
                       
                      <body>
                          <p> You can Add your Address Here :</p>
                       
                          <form id="frm1"  method="get" action="demo.htm">
                              write the address : <input  name="txtadd" type="text" id="txt1"> <br>
                              write a name for it! : <input name="txtcat" type="text" id="txt2"> <br>
                              choose your category: 
                              <select name="cat">
                                  <option value="1">ReadingEnglish </option>
                                  <option value="2"> ListeningEnglish </option>
                                  <option value="3"> WritingEnglish </option>
                                  <option value="4"> SpeakingEnglish </option>
                              </select>
                              <br>
                              <br>
                              <input name="btn1" type="button" onclick="passmain();" value="Click to Add it ! " ><br>
                          </form>
                      </body>
                      </html>
                      first:

                      document.getEle mentsByName('ca t') returns a node list ... and JavaScript always starts counting at 0 not 1 so in your code the value isn't retrieved

                      second:

                      the value isn't the option's text but its value ... so your conditions would never match ... you need to check for the value

                      third:

                      you didn't fix the curly brace issue either ... so basically the first error that occurs is a syntax error -> so use the shown switch statement and a clean indentation to avoid such simple errors ...

                      regards
                      thank u , it is showing and adding the text BUT
                      how can i add the link to it,
                      i mean when i click on the text show the link that user write in another text.

                      Comment

                      • elham477
                        New Member
                        • May 2010
                        • 22

                        #12
                        Originally posted by gits
                        there are more issues - i give you a new start to recode your script:

                        Code:
                        <html>
                        <head>
                        <script type="text/javascript">
                        
                        function formSubmit() {
                            document.getElementById('frm1').submit();
                        }
                        
                        function passmain() {
                            var val = document.getElementsByName('cat')[0].value;
                            
                            switch (val) {
                            case '1':
                                break;
                            case '2':
                                break;
                            }
                            
                            formSubmit();
                        }
                         
                        </script>
                        </head>
                         
                        <body>
                            <p> You can Add your Address Here :</p>
                         
                            <form id="frm1"  method="get" action="demo.htm">
                                write the address : <input  name="txtadd" type="text" id="txt1"> <br>
                                write a name for it! : <input name="txtcat" type="text" id="txt2"> <br>
                                choose your category: 
                                <select name="cat">
                                    <option value="1">ReadingEnglish </option>
                                    <option value="2"> ListeningEnglish </option>
                                    <option value="3"> WritingEnglish </option>
                                    <option value="4"> SpeakingEnglish </option>
                                </select>
                                <br>
                                <br>
                                <input name="btn1" type="button" onclick="passmain();" value="Click to Add it ! " ><br>
                            </form>
                        </body>
                        </html>
                        first:

                        document.getEle mentsByName('ca t') returns a node list ... and JavaScript always starts counting at 0 not 1 so in your code the value isn't retrieved

                        second:

                        the value isn't the option's text but its value ... so your conditions would never match ... you need to check for the value

                        third:

                        you didn't fix the curly brace issue either ... so basically the first error that occurs is a syntax error -> so use the shown switch statement and a clean indentation to avoid such simple errors ...

                        regards
                        cell_obj.innerH TML= document.getEle mentById('txt1' ).value
                        i should use this cod but change the "innerHTML"
                        what can i type instead it to show the link.

                        Comment

                        • gits
                          Recognized Expert Moderator Expert
                          • May 2007
                          • 5390

                          #13
                          you would need to create a real anchor element and set its href attribute - you might use the createElement(), appendChild() etc. DOM methods or use the innerHTML with a correct 'html-string'

                          Comment

                          • elham477
                            New Member
                            • May 2010
                            • 22

                            #14
                            Originally posted by gits
                            you would need to create a real anchor element and set its href attribute - you might use the createElement(), appendChild() etc. DOM methods or use the innerHTML with a correct 'html-string'
                            this text which insert in the table is temporary!!!
                            i want to insert it for always, it just insert for that moment when user add it.
                            and i dont know how can it refer to link ( i mean when i click it show a link in my frame in the first page)
                            iam really sorry for my qustions &so thankful for your reply.

                            Comment

                            • gits
                              Recognized Expert Moderator Expert
                              • May 2007
                              • 5390

                              #15
                              ?? ... so you would just need to add the information to a database ... or what is your exact question?

                              Comment

                              Working...