This is Interesting: Free Magazines for Graphics designers and webmasters  


Home > Archive > Dreamweaver > August 2004 > Refresh form problem (newbie)





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Refresh form problem (newbie)
gasma1975

2004-08-09, 7:14 pm

Hi,

I have a small form with 3 fields, VAL1, VA2, and SUM. OnClick I get the
result of VAL1 and VAL2, but immediatly after I clicked the button SUBMIT, I
can see the result but the page is refreshing automatically right after and I
loose all the values. HOW CAN I DISABLE IT ?

Thank you

Mick White

2004-08-10, 12:14 pm


See my previous answer, but:
<form onsubmit="return false">
<p><input name="val1" type="text" id="val1"</p>
<p><input name="val2" type="text" id="val2"></p>
<p><input type="button" name="Button" value="Add"
onclick="val3.value=Number(val1.value)+ Number(val2.value)"></p>
<p><input name="val3" type="text" id="val3"></p>
</form>

This is bare essentials,not necesarily cross-browser, no error checking.
And as you are using javascript, I'd recommend not using CAPS for your
form elements' names/ids. The use of CAPS as an identifier generally
suggests a constant or a global variable. (May as well start on the
right foot)

The recommended way:

<form onsubmit="return false">
<p><input name="val1" type="text" id="val1"</p>
<p><input name="val2" type="text" id="val2"></p>
<p><input type="button" name="Button" value="Add"
onclick="if(!isNaN(this.form.elements['val1'].value) ||
!isNaN(this.form.elements['val2'].value)){
this.form.elements['val3'].value=
Number(this.form.elements['val1'].value)+
Number(this.form.elements['val2'].value)}"></p>
<p><input name="val3" type="text" id="val3"></p>
</form>




Mick

gasma1975 wrote:

> Hi,
>
> I have a small form with 3 fields, VAL1, VA2, and SUM. OnClick I get the
> result of VAL1 and VAL2, but immediatly after I clicked the button SUBMIT, I
> can see the result but the page is refreshing automatically right after and I
> loose all the values. HOW CAN I DISABLE IT ?
>
> Thank you
>

Mick White

2004-08-15, 7:15 pm


See my previous answer, but:
<form onsubmit="return false">
<p><input name="val1" type="text" id="val1"</p>
<p><input name="val2" type="text" id="val2"></p>
<p><input type="button" name="Button" value="Add"
onclick="val3.value=Number(val1.value)+ Number(val2.value)"></p>
<p><input name="val3" type="text" id="val3"></p>
</form>

This is bare essentials,not necesarily cross-browser, no error checking.
And as you are using javascript, I'd recommend not using CAPS for your
form elements' names/ids. The use of CAPS as an identifier generally
suggests a constant or a global variable. (May as well start on the
right foot)

The recommended way:

<form onsubmit="return false">
<p><input name="val1" type="text" id="val1"</p>
<p><input name="val2" type="text" id="val2"></p>
<p><input type="button" name="Button" value="Add"
onclick="if(!isNaN(this.form.elements['val1'].value) ||
!isNaN(this.form.elements['val2'].value)){
this.form.elements['val3'].value=
Number(this.form.elements['val1'].value)+
Number(this.form.elements['val2'].value)}"></p>
<p><input name="val3" type="text" id="val3"></p>
</form>




Mick

gasma1975 wrote:

> Hi,
>
> I have a small form with 3 fields, VAL1, VA2, and SUM. OnClick I get the
> result of VAL1 and VAL2, but immediatly after I clicked the button SUBMIT, I
> can see the result but the page is refreshing automatically right after and I
> loose all the values. HOW CAN I DISABLE IT ?
>
> Thank you
>

Sponsored Links


Copyright 2003 - 2008 forum4designers.com  Software forum  Computer Hardware reviews