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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Onload and Onclick Issues !!!!!

Status
Not open for further replies.

gomirage

Programmer
Jun 3, 2003
28
0
0
US
Hello everyone,
I have a form with textboxes and submit button. I want to have default values in the textboxes when the form loads. so i set a Form onload procedure and the another procedure the submit button onclick event to perform the tasks i want to perform.
The problem is after the computation the textboxes are filled by the default values.
Now i want to know How to separate these two events (onload and onclick).

Thanks.
 
These are Javascript questions. Please see the Javascript forum, forum216.
 
Sorry for not being clear enough. It is an ASP question.

Here is what i want to do.

<% Option Explicit %>

<HTML>
<HEAD>
<%
dim Val1,Val2
%>

<Script Language=Javascript>

function DefaultValues()
{
document.form1.TxtVal1.value =1
document.form1.TxtVal2.value =2
}

function ClickSubmit()
{
document.form1.TxtVal1.value =3
document.form1.TxtVal2.value =4
}

</Script>
</HEAD>


 
The exact Code.

<% Option Explicit %>

<HTML>
<HEAD>
<TITLE> asp 1</TITLE>
<%
dim Val1,Val2
%>

<Script Language=Javascript>

function DefaultValues()
{
document.form1.TxtVal1.value =1
document.form1.TxtVal2.value =2
}

function ClickSubmit()
{
document.form1.TxtVal1.value =3
document.form1.TxtVal2.value =4
}

</Script>
</HEAD>


<Body onLoad=DefaultValues()>
<Form method=POST id=form1 name=form1>
<br> Value1 <INPUT type=&quot;text&quot; id=TxtVal1 name=TxtVal1 > <br>
<br> Value2 <INPUT type=&quot;text&quot; id=TxtVal2 name=TxtVal2 > <br>
<INPUT type=&quot;submit&quot; onClick=&quot;ClickSubmit()&quot; id=submit1 name=submit1>

</Form>
</Body>
</HTML>
 
well you'll have to explain more, where's the ASP.


Apart from declaring two variables there doesn't seem to be any.


Chris.


Indifference will be the downfall of mankind, but who cares?
 
Just above your post. I really dont know what i am missing here !!!!
:)
 
gomirage i am not able to understand put in an explanation of ur problem along with the ASP code...

Known is handfull, Unknown is worldfull
 
The posts must have crossed.


Well that make two of us missing something, I still don't see any asp using the two variables and nowhere in the form is there any attempt to use them



the javascript won't appear to work because when the form submits the values will go back to 1 and 2





Chris.

Indifference will be the downfall of mankind, but who cares?
 
Here we go.
I have 2 textboxes i want to load with default values(say 1 and 2). Then when i click th esubmit button i want the values to become 3 and 4.
But the problem is when i click i am getting the default value(1 and 2) instead of 3 and 4.
here is the code again.

<% Option Explicit %>

<HTML>
<HEAD>
<TITLE> asp 1</TITLE>
<%
dim Val1,Val2
%>

<Script Language=Javascript>

function DefaultValues()
{
document.form1.TxtVal1.value =1
document.form1.TxtVal2.value =2
}

function ClickSubmit()
{
document.form1.TxtVal1.value =3
document.form1.TxtVal2.value =4
}

</Script>
</HEAD>


<Body onLoad=DefaultValues()>
<Form method=POST id=form1 name=form1>
<br> Value1 <INPUT type=&quot;text&quot; id=TxtVal1 name=TxtVal1 > <br>
<br> Value2 <INPUT type=&quot;text&quot; id=TxtVal2 name=TxtVal2 > <br>
<INPUT type=&quot;submit&quot; onClick=&quot;ClickSubmit()&quot; id=submit1 name=submit1>

</Form>
</Body>
</HTML>



 
Here's what I think you're missing:[ul][li]Stuff inside
Code:
<%
and
Code:
%>
tags will be executed on the server, before the page is sent to the browser, and the browser will never see them.

[li]Stuff inside
Code:
<script>
and
Code:
</script>
tags will be executed on the browser and are completely ignored by the server.

[li]Never the twain shall meet (the two don't interact with each other at all).[/ul]
 
To further clarify, both the onclick and onload events are completely ignored by the server and have nothing whatsoever to do with ASP. Seriously, you have a Javascript question. I'm not kidding.

The little bit of ASP you do have (the Option Explicit and the Dim-ing of the variables) does indeed happen on the server and is indeed ASP, but it doesn't do anything and the browser never sees any of it. What you're trying to do has to do with client-side Javascript.

Really.
 
well you are getting exactly what should happen.
The submit button will submit the form back to itself and the onLoad event will trigger again


No ASP is involved anywhere in this code.



Chris.

Indifference will be the downfall of mankind, but who cares?
 
ok guys.
I will remove the client side and replace it with server scripts. To make it short is there any way to load a form with default values and repace them with other values at run time ?
 
Sure, you could have a page like this:
Code:
...after the head...

<body>
<form method=&quot;post&quot; action=&quot;ThisPageName.asp&quot; name=&quot;form1&quot;>
<%
'Create some server-side variables
Dim Val1, Val2
'Set their default values
Val1 = 1
Val2 = 2
'If this form has been submitted to this page
If Request.Form(&quot;submitted&quot;) = &quot;1&quot; Then
    'Set the variables to the new values
    Val1 = 3
    Val2 = 4
End If
%>
    Value1 <INPUT type=&quot;text&quot; name=&quot;TxtVal1&quot; value=&quot;<%=Val1%>&quot;><br>
    Value2 <INPUT type=&quot;text&quot; name=&quot;TxtVal2&quot; value=&quot;<%=Val2%>&quot;><br>
    <input type=&quot;submit&quot; name=&quot;submit1&quot;>
    <input type=&quot;hidden&quot; name=&quot;submitted&quot; value=&quot;1&quot;>
</form>
</body>
The
Code:
<%=SomethingHere%>
code tells ASP to write out the value of &quot;SomethingHere&quot; in that spot. In our case we want to write out the value of the server-side variables Val1 and Val2.
 
To clarify, what that script does is:[ol][li]The first time it's loaded the server-side variable &quot;Val1&quot; is set to 1 and &quot;Val2&quot; is set to 2.

[li]It then checks to see if the page received a POSTed bit of information called &quot;submitted&quot; and if it's equal to &quot;1&quot;. The first time the page is loaded it will not have received that information so nothing will happen.

[li]The form is drawn normally, and ASP will substitute the values of &quot;Val1&quot; and &quot;Val2&quot; into those input boxes as default values, in this case a 1 and a 2.

[li]When the user submits the form the values of the form are sent to this page, including a POSTed value called &quot;submitted&quot; with a value of &quot;1&quot;.

[li]&quot;Val1&quot; is set to 1 and &quot;Val2&quot; is set to 2, as before.

[li]This time there is something called &quot;submitted&quot; and its value is indeed &quot;1&quot;, so &quot;Val1&quot; is set to 3 and &quot;Val2&quot; is set to 4.

[li]The form is drawn normally, and ASP will substitute the values of &quot;Val1&quot; and &quot;Val2&quot; into those input boxes as default values just like before, but this time they'll be a 3 and a 4.[/ol]
Is this what you mean to do?
 
Thank you man,
That do it. I will adapt it to what i wanna do.
Again thank you for saving the night, lol

bye
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top