...

View Full Version : PLEASE HELP..VBSCRIPT/ASP/Javascript



pktyagi
06-03-2003, 04:36 PM
Hi,

I am developing a webpage and I need to write some VBscripts or Javascript function so that I can call this function when I select a customer number from a available drop-down list of customers. I mean at "Onchange" event. As soon as I select/change the customer number it should have to refresh the name & address details for that customer number. All the information (address, name etc.) need to be selected from database. I tried to write VBscript function using <Script> tagg but the problem is that I am unable to write a code in order to access the database. If i write the same logic/code in Vbscript with <% %> tags it doesn't recongnize the function call <%function_name()%> on "Onchange" event. Please Help me and let me know which kind of VBscript (tags) will be used. Is there anything I can write in Javascript in order to access the database?
Any Help is highly Appreciated.

Thanks.
Pktyagi

Roy Sinclair
06-03-2003, 05:08 PM
See point 1 here. (http://www.codingforums.com/postguide.htm)


Don't make the mistake of thinking you can run server side script or function in response to end user actions on the same page. You have to post to the server and get a whole page in response.

Kor
06-03-2003, 06:00 PM
i think u may have 2 possibilities:

1. use php or asp or whichever to generate your whole page from database.

Inside your page, there will be generate some javascript variables, say var address1 = "text address1 here", var address2 ="text address2 here" and so on.

Build an input text and give it a name. build a javascript function which writes those variables onto that input text. Onchange direct to that function, according to the selected Index.

<html>
<head>
<title></title>
<script language="JavaScript">
function change(){
var address1 = "text address1 here";
var address2 ="text address2 here";

var selval = document.forms[0].selectname.selectedIndex;
if(selval == 1){
document.forms[0].textfield.value = address1;
}
if(selval == 2){
document.forms[0].textfield.value = address2;
}
}
</script>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<form>
<select name="selectname" size="1" OnChange="change()">
<option selected>Choose name</option>
<option>name1</option>
<option>name2</option>
</select><br>
<br>
<br>
<br>
<input type="text" name="textfield" size="40">
</form>
</body>
</html>


Well, if there are a lot of data in the data base, you can optyimize the script using an array and/or a "for/to" cicle within the if sentences.

2. put the address in an iframe. Build a submit button near the select tag, in the same form, this time with a POST method to a CGI aplication who will build that iframe using data base.

That is what I can think it might work. We use something similar(the first ideea) in our page at http://www.amaltea.ro/comanda.php

Garadon
06-03-2003, 06:33 PM
and then there is the 3rd option. this is only to give u an idea

where u make a asp file that selects the customer data for one custormer in ur db by customernumber.:

thisCustomer.asp
this file end output should look something like this
document.forms[0].textfield.value = address2;


and u have your main fil

Customers.asp

<html>
<head>
<script src="" id="loader"></script>
<script language="JavaScript">
function change(){
var customerNr = document.forms[0].selectname.selectedIndex;

document.all.loader.src="thisCustomer.asp?CustomerNr="+customerNr;

}
}
</script>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<form>
<select name="selectname" size="1" OnChange="change()">
<option selected>Choose name</option>
<option>name1</option>
<option>name2</option>
</select><br>
<br>
<br>
<br>
<input type="text" name="textfield" size="40">
</form>
</body>
</html>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum