Populate second text box based on value extracted from first text box

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #31
    Are there any errors? If so, post the message(s) that you see.

    Is the PHP file called cd.php?

    Comment

    • sarega
      New Member
      • Oct 2008
      • 82

      #32
      Am not getting any errors its just that second text box is not getting populated, and the php file is called cd.php
      And one more thing can I include a javascript file in the header of the html file and still have more javascript functions in the same html file??

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #33
        The answer to your question is yes, you can.

        I just tested your code in Firefox and it works absolutely fine (except for undefined temporarily appearing which you can easily get rid of). Which browsers are you testing on?

        Comment

        • sarega
          New Member
          • Oct 2008
          • 82

          #34
          Ya now its working.....tha nks for all the help

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #35
            You're welcome. Glad it is!

            Did you make any changes? What was the problem in the end?

            Comment

            • sarega
              New Member
              • Oct 2008
              • 82

              #36
              I had another doubt, the php code can it have call to functions which are defined in a different directory?

              Comment

              • acoder
                Recognized Expert MVP
                • Nov 2006
                • 16032

                #37
                That's a PHP question, but yes. If you have problems on that front, start a new thread in the PHP forum.

                Comment

                • sarega
                  New Member
                  • Oct 2008
                  • 82

                  #38
                  Thanks for the help.....

                  Comment

                  • acoder
                    Recognized Expert MVP
                    • Nov 2006
                    • 16032

                    #39
                    You're welcome :) Post back to the forum if you have more questions.

                    Comment

                    • sarega
                      New Member
                      • Oct 2008
                      • 82

                      #40
                      hi, can I make the second text box readonly after populating it with a value? how to do it??

                      Comment

                      • zaphod42
                        New Member
                        • Oct 2008
                        • 55

                        #41
                        Code:
                        myElement.disabled=true
                        that works for pretty much all input type elements

                        Comment

                        • sarega
                          New Member
                          • Oct 2008
                          • 82

                          #42
                          Code:
                          #
                          #  "http://www.w3.org/TR/html4/loose.dtd">
                          #  <html>
                          #  <head>
                          #  <title>Untitled Document</title>
                          #  <script type="text/javascript">
                          #  function test1()
                          #  {
                          #  var a=document.getElementById("first").value;
                          #  var b=a.split('/');
                          #  var c=b[0];
                          #  var d=b[1];
                          #  if(c!="fog") {
                          #  document.getElementById("second").value="";
                          #  return;
                          #  }
                          #  xmlHttp=GetXmlHttpObject();
                          #  if(xmlHttp==null) {
                          #  alert("your browser does not support ajax");
                          #  return;
                          #  }
                          #  var url="cd.php";
                          #  url=url+"?d="+d;
                          #  url=url+"&sid="+Math.random();
                          #  xmlHttp.onreadystatechange=StateChanged;
                          #  xmlHttp.open("GET",url,true);
                          #  xmlHttp.send(null);
                          #  }
                          #  
                          #  function GetXmlHttpObject()
                          #  {
                          #  var xmlHttp=null;
                          #  try
                          #    {
                          #      // Firefox, Opera 8.0+, Safari
                          #        xmlHttp=new XMLHttpRequest();
                          #          }
                          #          catch (e)
                          #            {
                          #              // Internet Explorer
                          #                try
                          #                    {
                          #                        xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
                          #                            }
                          #                              catch (e)
                          #                                  {
                          #                                      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
                          #                                          }
                          #                                            }
                          #                                            return xmlHttp;
                          #                                            }
                          #  
                          # function StateChanged()
                          # {
                          # if (xmlHttp.readyState==4)
                          # {
                          # document.getElementById("second").value=xmlHttp.responseText;
                          # }
                          # }
                          # </script>
                          # </head>
                          # <body>
                          #  <input type="text" id="first" size="40" onkeyup="test1();"/><br><br>
                          #  <input type="text" id="second" size="40"/>
                          #  </body>
                          #  </html>
                          In this code how do I make the second text box readonly??
                          Last edited by acoder; Oct 21 '08, 07:35 AM. Reason: Added [code] tags

                          Comment

                          • zaphod42
                            New Member
                            • Oct 2008
                            • 55

                            #43
                            looks like line 57 is:

                            Code:
                             document.getElementById("second").value=xmlHttp.responseText;
                            I think if you add:
                            Code:
                            document.getElementById("second").disabled=true
                            before the close squigly ( ' } ' ) on line 58 it should do it

                            Comment

                            • sarega
                              New Member
                              • Oct 2008
                              • 82

                              #44
                              I have introduced a check box only if the check box is clicked only then the second text box has to be populated how can i check everytime whether the check box is clicked or not?

                              Comment

                              • sarega
                                New Member
                                • Oct 2008
                                • 82

                                #45
                                Code:
                                "http://www.w3.org/TR/html4/loose.dtd">
                                  <html>
                                  <head>
                                  <title>Untitled Document</title>
                                  <script type="text/javascript">
                                  function test1()
                                  {
                                  var a=document.getElementById("first").value;
                                  var b=a.split('/');
                                  var c=b[0];
                                  var d=b[1];
                                  if(c!="fog") {
                                  document.getElementById("second").value="";
                                  return;
                                  }
                                  xmlHttp=GetXmlHttpObject();
                                  if(xmlHttp==null) {
                                  alert("your browser does not support ajax");
                                  return;
                                  }
                                  var url="cd.php";
                                  url=url+"?d="+d;
                                  url=url+"&sid="+Math.random();
                                  xmlHttp.onreadystatechange=StateChanged;
                                  xmlHttp.open("GET",url,true);
                                  xmlHttp.send(null);
                                  }
                                  
                                  function GetXmlHttpObject()
                                  {
                                  var xmlHttp=null;
                                  try
                                    {
                                      // Firefox, Opera 8.0+, Safari
                                        xmlHttp=new XMLHttpRequest();
                                          }
                                          catch (e)
                                            {
                                              // Internet Explorer
                                                try
                                                    {
                                                        xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
                                                            }
                                                              catch (e)
                                                                  {
                                                                      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
                                                                          }
                                                                            }
                                                                            return xmlHttp;
                                }                                            }
                                  
                                 function StateChanged()
                                 {
                                  if (xmlHttp.readyState==4)
                                  {
                                  document.getElementById("second").value=xmlHttp.responseText;
                                  }
                                  }
                                  </script>
                                  </head>
                                  <body>
                                   <input type="text" id="first" size="40"/>
                                <input type="checkbox" id="third" onClick="test1()";/><br><br>
                                   <input type="text" id="second" size="40"/>
                                   </body>
                                   </html>
                                If only the the check box is clicked only then the second text box has to be populated, even for the first time the check box is clicked and then later if it is unchecked then it should not populate the second text box for the second time.
                                Can somebody plz help me??
                                Last edited by acoder; Oct 21 '08, 04:50 PM. Reason: Added [code] tags

                                Comment

                                Working...