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>
jt537Asked:
Who is Participating?
 
Michel PlungjanConnect With a Mentor IT ExpertCommented:
HS: simpler to use
onClick="this.form.recallStore.value = this.form.textBox.value"
and

this.form.textBox.value = this.form.recallStore.value;
this.form.textBox.focus();this.form.textBox.select()

But anyway, the value disappears when another page is loaded so the top.searchTerms is needed to persist the term across pages.

Michel
0
 
HolySpiritCommented:
jt537,
So, what would u like us to do for u.
-- Holy Spirit
0
 
HolySpiritCommented:
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
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
HolySpiritCommented:
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
0
 
Michel PlungjanIT ExpertCommented:
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
0
 
Michel PlungjanIT ExpertCommented:
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"><!-- //

;-)
0
 
HolySpiritCommented:
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
0
 
jt537Author Commented:
mplungjan's answer works best.
0
All Courses

From novice to tech pro — start learning today.