Click to See Complete Forum and Search --> : Iterating over form fields at client side


simonchambers
January 17th, 2003, 05:49 AM
Hi,

On a webform that I have created I need to be able to loop through a number of textbox values and determine if they are greater than a specified amount, before the form is submitted.

In the old asp architecture I would do the following:

<button .......on click='checkdetails(form,form.elements.length)'...>

this would then call a predefined javascript function that would look something like:

checkdeatils(form,x)
{
if(form.textbox1.value + form.textbox2.value = 33)
{
alert('ok your amonut is ok')
}
else
{
form.submit
}
}



What i need to do is get this same functionality into .net. It looks like this is done through the custom validation control, which I have got to call a javascript function. What I cannot do however is somehow get this function to reference more than one control/form value (i.e. multiple textboxes as above).

Can this be done??

Many Thanks

Simon:confused:

sager
January 17th, 2003, 04:30 PM
You need to look into the asp:RangeValidatorControl

Try

asp:RangeValidator id="RangeValidator1"
runat="server"
errormessage="This value is too low."
controltovalidate="tbValue"
Type=integer
MinimumValue="10"

simonchambers
January 20th, 2003, 03:41 AM
Hi,

yeh thanks, I already use the range validator fine for a single control, what I need to do however is comapre the values of several controls (12 to be exact), and need some way of referencing multiple controls in javascript/vbscript. The ranage validator and the other validators ask u to specify a single control, i.e. the 'control to validate', I almost need a :
'multiple controls to validate'.

I could do this in the old style of asp by passing the form and its values to a javasrcipt function, and then do something like:

if(form.textbox1.value + form.textbox2.value = 33)
{
......
}

but cannot see how to do this in .net, surely this can be done though???

Many Thanks

Simon

simonchambers
January 23rd, 2003, 09:25 AM
Hi,

In the end I used the html buttons in .net and not the web forms controls, as i managed to get the onclick=function1() within the button <input tag.

From there i used the standard document.form1.textbox1.value way.

I still don't know how to get this onclick to work from within the web forms buttons, have used the html control instead.

Simon