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!

javascript function causing asp page to reload??

Status
Not open for further replies.

nimarii

MIS
Jan 26, 2004
213
US
hello,

i have a list of editable text fields that are displayed dynamically. I need to be able to "disable" each field using either a checkbox or a button.

I added a lock image next to each editable field, with an "onclick" property that calls a function to disable the proper field.

However, when I call the function, it disables the proper field, but then reloads the entire page, and the field that should have been disabled is now enabled again, which is the default state.

here is the asp code:
Code:
<td align="center">					
<input type="text" name="txtInterestRate<%=i%>" size="10" value="<%=DisplayDecimal(strInterestRate,2)%>" >
<input type="image" name="LiborLock" onclick="LiborLock(<%=i%>)" src="file:///C:\Inetpub\[URL unfurl="true"]wwwroot\htdocs\images\lock.gif"></td>[/URL]

and here is the js function:
Code:
	function LiborLock(i)
	{
		var PaymentRecord = eval('document.aform.txtInterestRate' + i);
		if (eval('document.aform.txtInterestRate' + i).disabled==true)
		{
			PaymentRecord.disabled = false;
		}
		else
		{
			PaymentRecord.disabled = true;
		}
	}

I didn't think that js functions automatically reloaded the page. Any idea on how to overcome this problem?

Thanks!!
</td>
 
[1]
>[tt]<input type="image" name="LiborLock" onclick="LiborLock(<%=i%>)" src="file:///C:\Inetpub\wwwroot\htdocs\images\lock.gif"></td>[/tt]

Change it to img.

[tt]<[red]img[/red] name="LiborLock" onclick="LiborLock(<%=i%>)" src="file:///C:\Inetpub\ [red]/[/red]></td>[/tt]

[2] And improve on the function---it does not look good to my liking.
[tt]
function LiborLock(i)
{
var PaymentRecord = document.aform.[blue]elements['txtInterestRate' + i];
PaymentRecord.disable=!PaymentRecord.disabled;[/blue]
}
[/tt]
 
i dont think you can use the OnClick property with using "<img name>"....?
 
>i dont think you can use the OnClick property with using "<img name>"....?

Okay, keep thinking.
 
And what do you think <input type="image"> do? One more thing for you to keep thinking...
 
i'm currently trying this, let me know what you think:

<a href="#" onClick="functionname()"><img src="..."></a>

having some problems with it though, error message says: "object doesnt support this property or method"

agh!!
 
You try everything, just not mine. It is up to you really.
 
i tried the <input type="image">. it doesnt allow for an onClick property.

thanks anyway.
 
Look, am I proposing input type="image" or it is you who posted it and I correct it for you? What kind of nonsense are you talking?
 
well - i solved the issue by using checkboxes, rather than an image.
 
? onclick works fine on the image tag, test this.

Code:
<img src="test.gif" onclick="alert('test')">
 
Nope, for example, if you test this,

Code:
<html>
<body>
<script language="Javascript">
onload=alert('loaded');
</script>
<img src="test.gif" onclick="alert('Hi')">
</body>
</html>

after clicking the image you'd get the "loaded" alert for the second time, if it did reload the page, but it shouldn't and doesn't.
 
nimarii,

tsuji has given you a perfectly valid solution, and you've chosen to ignore it, pretending you know better, but getting it wrong most of the time.

Why did you bother asking the question if you were not willing to listen to, and take advice from, the answers given?

Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top