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
The FormPHP 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>
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
The ScoreMethod.phpPHP Code:<div id="divScoringMethod"></div><iframe src="about:blank" name="hiddenFrame" width="0" height="0" frameborder="0"></iframe>
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.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>



Watisfy - Weight Control Made Easy

Bookmarks