Click to See Complete Forum and Search --> : Stop a onChange event depending on with object is triggered
Hello,
I'm trying to make a lookup-function...
I've got a form with several textboxes (normal fields). After the first textbox, I've got a button, who will be used to lookup data (address-code i.e.)
Now, when I fill in my textbox and I leave it, the onChange will be fired to check if my data is correct.
BUT, if I fill in my textbox, and I push on the lookup-button, the onChange may not be fired!
Is their an efficient way to work this out?
Kind Regards,
Luc SLenders
AdamBrill
12-30-2002, 12:37 PM
If you put the onchange in the <textarea> (or <input>, whichever you used...) tag, it should run every time. Maybe you could try posting your code, it is possible that something else is stopping the onchange code. If you post it, I'll take a look...
Craiga
12-30-2002, 02:07 PM
You might try on onsubmit in the form:
<script>
function checkForm(f){
// Simple check to see if is number and is 3 chars long
if(f.area_code.valuelength == 3 &&
!isNaN(f.area_code.value)){
return true;
}else{
alert('Invalid Area Code');
return false;
}
}
</script>
<form onsubmit="return checkForm(this)">
<input type="text" name="area_code">
<input type="submit">
</form>
Below you can find a example of my problem. I hope you can see witch is my problem...
Thx a lot for take a look at this...
<html>
<head>
<title>Lookup Example</title>
<SCRIPT LANGUAGE="JavaScript">
function valueChanged(pFieldName)
{
window.update.LookupField.value = pFieldName
window.update.submit()
alert("Check CustomerID - May not be done when the lookup button is clicked!!!")
// the page will be posted... The server will seach for the customercode that is filled in
// If Customercode exists -> in the Address field will come the Address of the customer.
}
function openLookup(pTable)
{
// this will open a new window with a list of the customers.
// in my appl. it is possible to click on a customer in the table and the CustomerID is filled in in the field Customer
hWin = window.open("customers.htm?table=" + pTable)
}
</script>
<BODY>
<FORM NAME="update" METHOD="post">
<table>
<tr>
<td> CustomerID
</td>
<td> <input type="hidden" name="LookupField">
<input type="text" name="CustomerID" size="20" onChange="valueChanged('CustomerID')">
</td>
<td> <input type="button" name="LookupBtnCustomer" value="Lookup" onClick="openLookup('Customers')" size=20>
</td>
</tr>
<tr>
<td> Address of Customer
</td>
<td> <input type="text" name="Address" size="20">
</td>
</tr>
<td> Some other data:
</td>
<td> <input type="text" name="SomeData" size="20">
</td>
</tr>
</table>
</form>
</BODY>
</html>
Craiga,
I think your option is not possible for my problem (or I can't see it clearly).
In the OnChange I submit (post) my page to get the discription of a code. But, if I like to seach my code (by pressing on a button to get an overview of my codes), the page may not be submitted.
I hope that the example-code is a bit clearly (posted some days ago).
Thx a lot,
Luc
Dave,
I tried this, and it works... thx
But, I think is slows down a bit...
I tried somethings else... the OnMouseDown. This event is triggered before the OnChange.
Now I have some other question. Witch is the syntax to check witch object has got focus, to see if my textbox is leaving?