Buttons

Chris Kelleher

Administrator
Staff member
Suppose I have a list of customers on the screen with behind each
customer an "Update" button that takes the user to a screen where
that particular customer can be updated.

What is the best way to achieve this (i.e. pass the customer number
to the update program)?

Peter
 

Chris Kelleher

Administrator
Staff member
Not sure if the question is "what's the best method of passing
the data" or "what piece of data do I pass". So here's both,
the second one first.

You can pass either the customer number or potentially the
ROWID. The ROWID can sometimes change, but only if the
same Customer Number was both deleted and then readded
again since the time you displayed it on the screen. It
would be much more likely the record simply was deleted
and checking on ROWID or Customer number would give
the same result. If customer number is something you
don't want to be showing people, try ROWID instead.
Otherwise they're close in terms of usability.

As to how - the WebSpeed Handbook covers the three methods.
There are three, three, and only three methods of passing
data from page to page. The URL, cookies, and fields.
(both hidden and not) Cookies should be used as little
as possible as they can be refused. Since you're not
asking the user for the input (you know it already), a
field would use a hidden one. There's nothing wrong with
this under the circumstances but it's awkward when you
have a list of 20 customers on the screen. 20 customers
equates to 20 different <FORM>'s in your HTML. Save that
for when you are prompting the user for input and have
only one <FORM>. In this case I'd make each customer number
a link instead of using a button. That's the easiest way
to build the URL into the A HREF=. If you really like
the button idea, then use an onSubmit JS trigger to go
the a URL with the customer no/ROWID built into it.


=================================================================
Geoff Crawford Phone: (973) 361 - 4224
Innovative Client Servers FAX: (973) 537 - 6946
75 Fleetwood Drive, Suite 200 Email: geoff@innov8cs.com
Rockaway NJ 07886 Web: http://www.innov8cs.com
Orange and Black Forever
 

Chris Kelleher

Administrator
Staff member
OK the link solution is fine in this case, but just out of
curiosity: would there be a drawback if I generated 20 different
forms? Is there a limit somewhere?

Peter
 

Chris Kelleher

Administrator
Staff member
I usually define one form on the top of the page with hidden fields for
customer number, etc.

<BLOCKQUOTE><font size="1" face="Arial, Verdana">code:</font><HR><pre>
&lt;form name="theform" action="EditCustomer"&gt;
&lt;input type=hidden name="CusID" value=""&gt;
&lt;/form&gt;
[/code]

Then I define a function like this:

<BLOCKQUOTE><font size="1" face="Arial, Verdana">code:</font><HR><pre>
function SendValues(CusID)
{
theform.CusID.value=CusID

/* you could also modify these:
theform.target="SomeOtherTarget";
theform.action="SomeOtherProgram";
*/

theform.submit();
}
[/code]

Then (in the customer list) I use a link or a button (normal button, not
submit).

In case of a link, use

<BLOCKQUOTE><font size="1" face="Arial, Verdana">code:</font><HR><pre>
&lt;a href="javascript: return SendValues(' CustomerNumberFromWS ');"&gt;
[/code]

In case of a button:

<BLOCKQUOTE><font size="1" face="Arial, Verdana">code:</font><HR><pre>
&lt;input type=button onClick="SendValues(' CustomerNumberFromWS ');"
value="edit"&gt;
[/code]

At the "CustomerNumberFromWS", you insert the customer number in your
webspeed code. Then you have one form that handles x customers in your
customer list, and you can add a whole bunch of other hidden fields which
you don't have to repeat for each customer.

Ronny Ager-Wick
Novare Consult AS
 

Chris Kelleher

Administrator
Staff member
Yeah, I forgot;
If you use the link (not the button), then the javascript function has to
return false. Just put "return false" in the end of the func. or else the
browser will (somtimes?) try to find link to the javascript function, which
naturally doesn't go very well.
 

Chris Kelleher

Administrator
Staff member
...second time lucky.

As far as i know there will be no limit to the amount of forms you can put
onto an HTML page, however...

I would do this without using forms, just use javascript in the onclick
event to change the self.location parameter.

If you want to use a form, a better way (i think) than building a gazillion
forms is to have one form using multiple submit buttons. Each submit button
should have a different value. (i.e. "Update Customer 1", "Update Customer
2" etc) When the form is submitted, you can check the value of the forms
"submit" button and take action accordingly.
HTH.
Mezz.
 
Top