Link to home
Start Free TrialLog in
Avatar of jt537
jt537

asked on

recall last entry

I would like to only recall the last entry.


input text box that I wish to save/call the last entries

<form name="myform">
<input type="text" name="mytext"><br>
<a href="javascript:getSearch(document.myform.mytext)">Go</a><br>
<a href="javascript:addSearch(document.myform.mytext.value)">Previous</a>
</form>




<html>
<head><title>Untitled</title>
<SCRIPT LANGUAJE="javascript">
<!--
searchTerms = new Array();
maxTerms = 10;
curTerm = -1;
totalTerm = 0
actualTerm = 0

function addSearch(theTerm) {
 top.curTerm++;
 top.searchTerms[top.curTerm] = theTerm;
 if (top.curTerm >= top.maxTerms) top.curTerms = -1;
 totalTerm++
 if (totalTerm==maxTerms+1) totalTerm--
}
function getSearch(theField) {
 if (totalTerm == 0) return true
 theField.value = top.searchTerms[actualTerm]
 actualTerm++
 if (actualTerm == totalTerm || actualTerm == maxTerms+1) actualTerm=0
 theField.focus();
 theField.select();
}

// -->
</SCRIPT>
</head>
<body>
<form name="myform">
<input type="text" name="mytext"><br>
<input type="button" value="recall" onclick="getSearch(document.myform.mytext)"><br>
<input type="button" value="save" onclick="addSearch(document.myform.mytext.value)">
</form>
</body>
</html>
</html>
Avatar of HolySpirit
HolySpirit

jt537,
So, what would u like us to do for u.
-- Holy Spirit
jt537,
So u can do this to only recall the last entry :

Source code
========================================
<html>
<head><title>Untitled</title>
<SCRIPT LANGUAGE="javascript">
<!--
searchTerms = new Array();
maxTerms = 10;
curTerm = -1;
totalTerm = 0
actualTerm = 0

function addSearch(theTerm) {
 top.curTerm++;
 top.searchTerms[top.curTerm] = theTerm;
 if (top.curTerm >= top.maxTerms) top.curTerms = -1;
 totalTerm++
 if (totalTerm==maxTerms+1) totalTerm--
}
function getSearch(theField) {
 if (totalTerm == 0) alert("No entry recorded !")
 else
 {
   actualTerm = top.searchTerms.length - 1;
   theField.value = top.searchTerms[actualTerm]

   theField.focus();
   theField.select();
  }
}

// -->
</SCRIPT>
</head>
<body>

<form name="myform">
<input type="text" name="mytext"><br>
<a href="javascript:getSearch(document.myform.mytext)">Recall entry</a><br>
<a href="javascript:addSearch(document.myform.mytext.value)">Save entry</a>
</form>
</body>

It will now recall the last item only

<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>
So can i solve your problem ?
<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>

-- Holy Spirit
jt537,
P.S. Although it have a better solution to this question, but i don't use it because it will rewrite most of the script that u have given me.
-- Holy Spirit
Avatar of Michel Plungjan
One entry is so simple:

<html>
<head><title>Untitled</title>
<SCRIPT LANGUAJE="javascript"><!-- //
searchTerms = "";
// --></SCRIPT>
</head>
<body>
<form name="myform">
<input type="text" name="mytext"><br>
<input type="button" value="recall" onclick="this.mytext = top.searchTerms"><br>
<input type="button" value="save"
onclick="top.searchTerms= this.myText.value">
</form>
</body>
</html>

Michel
Too simple! forgot a form and a value:

<input type="button" value="recall"
onclick="this.form.mytext.value = top.searchTerms"><br>
<input type="button" value="save"
onclick="top.searchTerms= this.form.myText.value">


And it is still
<SCRIPT LANGUAGE="javascript"><!-- //

;-)
jt537,
How about this script, it use a hidden field to store the value ^_^:
<form name = test>
<input name = textBox type = text>
<input name = recallStore type = hidden>
<input type = button onClick = "document.forms.test.recallStore.value = document.forms.test.textBox.value" value = Store>
<input type = button onClick = "document.forms.test.textBox.value = document.forms.test.recallStore.value;document.forms.test.textBox.focus();document.forms.test.textBox.select()" value = Recall>
</form>
-- Holy Spirit
ASKER CERTIFIED SOLUTION
Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jt537

ASKER

mplungjan's answer works best.