Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Clear form information 1

Status
Not open for further replies.

florida41

Technical User
May 13, 2004
95
US
I have several entries for Visitors where I would like to have Clear/Reset link for each Visitor information so someone could clear an entry for a specific Visitor before submitting the form.

My attempt is not working. Please advise.


Code:
Visitor One Information<br>
Visitor One<input type="Text" name="Visitor"><br>
City One<input type="Text" name="City"><br>
<a href="#" onclick="return vis1();">Clear/Reset Visitor 1 Info</a><br><br>

Visitor Two Information<br>
Visitor Two<input type="Text" name="Visitor2"><br>
City Two<input type="Text" name="City2"><br>
<a href="#" onclick="return vis2();">Clear/Reset Visitor 2 Info</a>

My JavaScript part:
Code:
function vis1()
{
var e = document.thePage;
    if((e.Visitor.value != "") && (e.City.value != "")) //if data is populated
	{
         e.Visitor.value == "";  //clear field value
         e.City.value == "";
	}
}

function vis2()
{
var e = document.thePage;
    if((e.Visitor2.value != "") && (e.City2.value != ""))
	{
         e.Visitor2.value == "";
         e.City2.value == "";
	}
}


 
It is important that you make JavaScript as reusable as possible. There is no need to create two functions to perform this action. I've re-coded your JS for you.

Your new JavaScript:

Code:
<script language="javascript" type="text/javascript">
<!--

function clearVisitor(which) {
    var f = document.forms['thePage'];
	f.elements['Visitor' + which].value = '';
	f.elements['City' + which].value = '';
}

-->
</script>

Your new calls to the function:

Code:
Visitor One Information<br>
Visitor One<input type="Text" name="Visitor1"><br>
City One<input type="Text" name="City1"><br>
<a href="#" onclick="clearVisitor(1); return false;">Clear/Reset Visitor 1 Info</a><br><br>

Visitor Two Information<br>
Visitor Two<input type="Text" name="Visitor2"><br>
City Two<input type="Text" name="City2"><br>
<a href="#" onclick="clearVisitor(2); return false;">Clear/Reset Visitor 2 Info</a>

*cLFlaVA
----------------------------
Lois: "Peter, you're drunk!"
Peter: "I'm not drunk, I'm just exhausted from stayin' up all night drinking!
 
cLFlaVa:
I seem to remember reading somewhere that "which" is a reserved keyword in some browsers. Correct me if I'm wrong.

florida41:
If you have compatibility issues, try changing the variable.

--Chessbot

"See the TURTLE of enormous girth!"
-- Stephen King, The Dark Tower series
 
I've never come across it - will look into it.

*cLFlaVA
----------------------------
Lois: "Peter, you're drunk!"
Peter: "I'm not drunk, I'm just exhausted from stayin' up all night drinking!
 
It's not reserved, at least not on the list I found.

--Chessbot

"See the TURTLE of enormous girth!"
-- Stephen King, The Dark Tower series
 
But, to your point - it is certainly a reserved word in some scripting languages. Many of which utilize classes.

*cLFlaVA
----------------------------
Lois: "Peter, you're drunk!"
Peter: "I'm not drunk, I'm just exhausted from stayin' up all night drinking!
 
which" is a property of the Event object (at least in NS). From DevGuru:
This property returns a number that represents either which mouse button (1 being the left button, 2 the middle and 3 the right) was pressed or which key was pressed (its ASCII value) at the time the event occuered.

Adam
while(ignorance){perpetuate(violence,fear,hatred);life=life-1};
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top