SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2006
    Location
    Closer than you think
    Posts
    149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Ajax and OnUpdate

    Ok I have a snippet of AJAX with some JavaScript.

    I have a list of formulas (Drop Down Menu) and a different Variables (2 Text Fields) When the user selects a formula the ajax portions goes to the database and gets the formula. Below the formula drop down menu is the text fields that allow the user to enter the variables. The Problem is that if they go back and change the formula their values they entered are not updated unless they retype. So I guess I am looking for an onload or something but my exposure is very limited.

    Here are my Code Snippets thus far.

    The JavaScript

    PHP Code:
    <script type="text/javascript">
            function 
    requestScoringMethod() {
                var 
    sId document.getElementById("ScoringMethodSelect").value;
                
    top.frames["hiddenFrame"].location "Ajax/ScoreMethod.php?id=" sId;
            }
            
            function 
    displayScoringMethod(sMethod) {
                var 
    divScoringMethod document.getElementById("divScoringMethod");
                
    divScoringMethod.innerHTML sMethod;
            }
        
    </script>
        <script src="../functions/FormManager.js">
    </script>

    <script type="text/javascript">
    window.onload = function() 
    {
        setupDependencies('Season'); //name of form(s). Seperate each with a comma (ie: 'form1', 'form2' )
    };
    </script>
    <script>
    function update(input) {
        
            var factor = document.forms.Season.factor.value
            var factor2 = document.forms.Season.factor2.value
            
            document.
            getElementById("factor").
                innerHTML 
                    = factor
                    
            document.
            getElementById("factor2").
                innerHTML 
                    = factor2


    }
    </script> 
    The Form
    PHP Code:
     <form action="<?PHP echo $_SERVER['PHP_SELF']; ?>" name="Season" method="post"><table> <tr>
            <td>Scoring Method: </td><td><select id="ScoringMethodSelect" name="scoring_method" style="width:130px; height:17px; font-family:tahoma; font-size:10px; color:#737272" onChange="requestScoringMethod()">
              <option value="A">Formula1</option>
              <option value="B">Formula2</option>
            </select></td>
            </tr>
          <tr>
            <td>Factor: </td>
            <td><input name="factor" onkeyup="update(this)" type="text"  maxlength="3" value="<?php echo "$factor"?>" /></td>
            </tr>
          <tr>
            <td>Percent A: </td>
            <td><input name="factor2" onkeyup="update(this)" type="text"  maxlength="3" value="<?php echo "$factor2"?>" />
     %        </td>
            </tr></table></form>

    Where the Code result is displayed
    PHP Code:
    <div id="divScoringMethod"></div><iframe src="about:blank" name="hiddenFrame" width="0" height="0" frameborder="0"></iframe
    The ScoreMethod.php

    PHP Code:

    // Some Processing Code


    // The JS

        <script type="text/javascript">
            window.onload = function () {
                var divInfoToReturn = document.getElementById("divInfoToReturn");
                
                parent.displayScoringMethod(divInfoToReturn.innerHTML);         
            };
        
        </script>

    // The Return Div
    </head>
    <body>
        <div id="divInfoToReturn"><?php echo $score_desc ?></div>
    </body>
    </html>
    So basically I need the Orginial Page to reload factor and factor2 variables even when the Ajax portion reloads the divScoringMethod I need the ID inside that div to reload as well. Please let me know if this is clear enough or if you need an working example.

  2. #2
    SitePoint Member
    Join Date
    Dec 2006
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ... The Problem is that if they go back and change the formula their values they entered are not updated unless they retype ...

    What you mean by 'go back'? Clicking on the 'back' buttom on the browser?
    Please provide more details :-)
    PS: You code shows you are not using 'pure' ajax.
    Watisfy - Weight Control Made Easy
    Ruby on rails and Ajax
    http://www.watisfy.com/
    Quanjumps Team, HM, NZ.

  3. #3
    SitePoint Zealot
    Join Date
    Jul 2006
    Location
    Closer than you think
    Posts
    149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When saying back I mean like Backup As in they Selected a Method, Entered Values for Factor and Factor2. Then they decided they wanted to select another Method from the Drop down menu. The new Method is loaded and the Factor and Factor2 Values are lost.

    Does that clarify?

  4. #4
    SitePoint Zealot
    Join Date
    Jul 2006
    Location
    Closer than you think
    Posts
    149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I solved this problem.

    Quote Originally Posted by WeakestLink View Post

    Where the Code result is displayed
    PHP Code:
    <div id="divScoringMethod"></div><iframe src="about:blank" name="hiddenFrame" width="0" height="0" frameborder="0"></iframe
    PHP Code:
    <div id="divScoringMethod"></div><iframe onload="update()" src="about:blank" name="hiddenFrame" width="0" height="0" frameborder="0"></iframe


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •