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

Form content and OnChange

Status
Not open for further replies.

Mute101

Programmer
Jun 28, 2001
428
GB
I have a form upon which a user can select from a list of account numbers. When the user selects the account number I have 2 form fields which I need to change reflecting the account name and an email address associated with the account.

How exactly would be the best way to go about this?

My thoughts were maybe an array populated on the form open could hold the information and I could pull it directly out of the array using the onchange event. The problem with this is it means writing in javascript, and I have a bit of a hate/hate relationship with anything java.

Is there any way I can do this in pure ASP, excepting the onchange event handler. All the information I need is stored on a SQL2000 server so a db call is necessary somewhere anyway.

Hope this is clear and someone can help.

Simon ----------------------------------------
Of all the things I have lost in my life, the thing I miss the MOST is my mind!
----------------------------------------
 
Off the top of my head, without thinking too much about whether I could actually get your array method to work, you would require javascript and it would probably be a bit cumbersome.

You could do it in ASP by firstly building a drop-down using values from the DB, then submitting the page (preferably to itself). You could submit the page on the onChange event if you wanted: onChange="frmForm.submit()"

Use the account number value from the chosen option to build an SQL statement to get the respective account name and email address.

strSQL = "SELECT Account_Name, Email_Addr FROM Accounts WHERE Account_Number = " & request.form("Account_Number") & ";"
 
Thanks for the info,

If I create the self referencing form what kind of trigger could I use to dynamically change the action of the form so I can continue with the process after my user has selected his account?

Bearing in mind the user may change account more than once on this page I need something that isn't a one shot deal that changes the action as soon as the account number is selected.

Thanks again
Simon ----------------------------------------
Of all the things I have lost in my life, the thing I miss the MOST is my mind!
----------------------------------------
 
Can't you just have the action as the page's name? This should allow you to resubmit as many times as you like, and it will rebuild the data according to the submitted Account Number.

However, to dynamically change the form action, use something like this:

function ChangeAction(input values) {
if (whatever) {
document.formName.action='pageName.asp';
document.frmName.submit()
}
else {
document.frmName.action='pageName2.asp';
document.frmName.submit()
}
}
 
The form is part of an ongoing process so I need to be able to resubmit to change the account details and then have a different action when the user is ready to move on to the next part of the process.

My question was what goes in the:

if (whatever)

part of the javascript in my instance? ----------------------------------------
Of all the things I have lost in my life, the thing I miss the MOST is my mind!
----------------------------------------
 
Ok, if I understand correctly, say you have three operations you want to achieve on your page:

1. Load account name and email address onChange of select box.

2. Button to process the page in one way and go somewhere else.

3. Another button to do something else.

you can use

for 1:
<select name=&quot;Account_Number&quot; onChange=&quot;chooseProcess('Acc_Details')&quot;>

for 2:
<input type=&quot;button&quot; name=&quot;button1&quot; value=&quot;Button 1&quot; onClick=&quot;chooseProcess('Other_Process_1')&quot;>

for 3:
<input type=&quot;button&quot; name=&quot;button2&quot; value=&quot;Button 2&quot; onClick=&quot;chooseProcess('Other_Process_2')&quot;>


then your javascript:

<script type=&quot;text/javascript&quot;>
<!-- begin
function chooseProcess(inVal) {
if (inVal == 'Acc_Details') {
document.formName.action='pageName.asp';
document.frmName.submit()
}
else if (inVal == 'Other_Process_1') {
document.frmName.action='otherPage.asp';
document.frmName.submit()
}
else {
document.frmName.action='otherPage.asp';
document.frmName.submit()
}
}
// end -->
</script>

You can use that for as many options or forms as you want (just modify the frmName accordingly). Hope that helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top