?
Solved

vbscript - onchange how to do I affect input fileds in an asp-page

Posted on 2003-03-04
15
Medium Priority
?
601 Views
Last Modified: 2010-08-05
I have a dropdown list (in a asp page) with for example 4 values, 100 , 200, 300 and 400. If the user hit for example 300 I want an input field in the page to get the value C anf show that value immediately.

How do I do that ?

Br Key
0
Comment
Question by:keyan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 3
  • 2
  • +1
15 Comments
 
LVL 15

Expert Comment

by:gladxml
ID: 8070007
keyan,

something like this...

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
</head>

<body bgcolor="#FFFFFF" text="#000000">
<form name="form1" method="post" action="">
<select name="select1" onchange = "javacript:document.form1.textfield.value=document.form1.select1.value">
    <option value="100">100</option>
    <option value="200">200</option>
    <option value="300">300</option>
    <option value="400">400</option>
  </select>
 <input type="text" name="textfield">
</form>
</body>
</html>
0
 
LVL 15

Expert Comment

by:gladxml
ID: 8070022

<html>
<head>
keyan,


Or something like this...

<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
</head>

<body bgcolor="#FFFFFF" text="#000000">
<form name="form1" method="post" action="">
<select name="select1" onchange = "javascript:form1.submit();">
    <option value="100">100</option>
    <option value="200">200</option>
    <option value="300">300</option>
    <option value="400">400</option>
  </select>
 <input type="text" name="textfield" value="<%=request.form("select1")%>">
</form>
</body>
</html>
0
 
LVL 15

Expert Comment

by:gladxml
ID: 8070025
keyan,

oops some typo..

Or something like this...

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
</head>

<body bgcolor="#FFFFFF" text="#000000">
<form name="form1" method="post" action="">
<select name="select1" onchange = "javascript:form1.submit();">
   <option value="100">100</option>
   <option value="200">200</option>
   <option value="300">300</option>
   <option value="400">400</option>
 </select>
<input type="text" name="textfield" value="<%=request.form("select1")%>">
</form>
</body>
</html>
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 1

Expert Comment

by:JennyRo
ID: 8070116
gladxml (or anyone else)

I hope you don't mind if I ask some side questions about this. (I would give some points if I had any - maybe later..)

action=""   ...is this the format if the contents of form are merely being used on same page as form?

Also, being new to these topics I am a bit confused about onchange, onclick etc. Are these just javascript commands? (I know a smidgen of vbscript but no javascript.)

Can you use javascript and vbscript interchangeably, and if so, do you have to state which language each time you change?

Much appreciated if anyone can answer and I will award points when I get some...promise!!

0
 
LVL 10

Accepted Solution

by:
apollois earned 400 total points
ID: 8070180
You will need to add an onchange event code to your SELECT statement, and a javascript function to process the onchange.  Here is example code.  Feel free to post follow-up questions.

Best Regards,
>apollois<

====================================
<html>
<head>

<SCRIPT language="javascript">

function setText(pobjSelect, pstrTextName) {
     var oText

     oText = eval('document.' + pobjSelect.form.name + '.' + pstrTextName)
     oText.value = pobjSelect.options(pobjSelect.selectedIndex).value

     return
}

</SCRIPT>

<title>New Page 1</title>
</head>

<body>

<form method="POST" name="MyForm">
     <p>Make a choice: <select size="1" name="MyList" onChange="setText(this, 'MyText');">
     <option selected>-- Select One --</option>
     <option value="A">100</option>
     <option value="B">200</option>
     <option value="C">300</option>
     <option value="D">400</option>
     </select></p>
     <p>MyText: <input type="text" name="MyText" size="20"></p>
     <p><input type="submit" value="Submit" name="Submit"></p>
</form>

</body>

</html>
============================================================

0
 
LVL 15

Expert Comment

by:gladxml
ID: 8070447
keyan,

<<<<<<<<
action=""   ...is this the format if the contents of form are merely being used on same page as form?
<<<<<<<

By default if the value of the action is null it will submit on the same page... But you can put the name of the page... But as for my example using the third post the page submit the form to itself..


>>>>>
Also, being new to these topics I am a bit confused about onchange, onclick etc. Are these just javascript commands? (I know a smidgen of vbscript but no javascript.)
>>>>>>

Yes it a vbscript and javascript command but this client side function and can only be used in client side scripting..

>>>>>>>>
Can you use javascript and vbscript interchangeably, and if so, do you have to state which language each time you change?
>>>>>>>>>

Yes you can use it but it is much better to use javascript rather vbscirpt becuase cross browser compatible unlike vbscript which is sometimes had some problem with netscape...


On my example you will see that i used javascript

<select name="select1" onchange = "javacript:document.form1.textfield.value=document.form1.select1.value">
   
But you can also used vbscript

<select name="select1" onchange = "vbscript:document.form1.textfield.value=document.form1.select1.value">

HTH...

HAppy programming...



0
 
LVL 15

Expert Comment

by:gladxml
ID: 8070495
keyan,

Remember asp uses vbscript as it default language when coding server side script so dont confuse yourself with client and server side scripting....

<<<<<<
I hope you don't mind if I ask some side questions about this. (I would give some points if I had any - maybe later..)
<<<<<<

No problem...

Here is a good tutorial that you can check... great online turorial

http://www.w3schools.com/


HTH...

HAppy programming...

0
 

Author Comment

by:keyan
ID: 8071014
If I want only use vbscript, how do I do then ? I would like to fetch data from a database depending on the the value in dropdown, make a calculation and then put the result in another input field. Brgds Keyan
0
 
LVL 10

Expert Comment

by:apollois
ID: 8072386
keyan,

>>>If I want only use vbscript, how do I do then <<<

If you do, then you page will only work in Microsoft IE.  It's the only browser that supports vbscript.  Plus, almost all client-side code examples on the Internet, and in books, is written in JavaScript.  You won't find much support for client-side VBScript.

>>> I would like to fetch data from a database depending on the the value in dropdown, make a calculation and then put the result in another input field<<<

This can be done.  YOu will need to post a new question to address this.

Good luck on your project.

Best Regards,
>apollois<
0
 
LVL 1

Expert Comment

by:JennyRo
ID: 8074895
Thanks heaps gladxml

You have helped clear things up greatly.

One more thing though, you said onchange etc are also used in vbscript, but when I tried a simple example using onclick to change a word to a different colour it didn't work in vbscript, only javascript. The w3schools site doesn't approach these commands in the vbscript TA at all. Could you possibly show me a very simple script using onclick in vbscript? Much appreciated.

I will get some points to you as soon as I have a decent amount to give.

BTW it was me (JennyRo) not keyan that asked the side questions.

Cheers
Jenny
0
 
LVL 15

Expert Comment

by:gladxml
ID: 8076008
keyan,

Does my first comment does not answer your question? Cause the code that I had posted has been tested and work fine here with me... What is the problem my code...


Regards,
gladxml



0
 
LVL 15

Expert Comment

by:gladxml
ID: 8077878
Keyan,

Whats up... I just want to know if you did test the code that I had posted...

Here is what you are looking for....

http://www.experts-exchange.com/Web/Web_Languages/ASP/Q_20443483.html



JennyRo,

I suggest that you use javascript on your client side scripting... Because vbscript client side scripting work only in IE...

Anyway here is an example that you are trying to accomplish... using Vbscript...

Onclick change the color of the text...

============

<HTML>
<HEAD>
<TITLE>VBSCRIPT SAMPLE BY GLADXML</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#0000FF">
<H2>SAMPLE ONCLICK USING VBSCRIPT</H2>
<HR>
<BR>
<font color="black" id="Text2" onclick="changecolor()">onclick</font>
<script language="VBScript">
flag=0
Sub changecolor
  If (flag=0) then
    flag=1
    Text2.color = "red"
  Else
    flag=0
    Text2.color = "black"
  End If
End Sub
</script>
<HR>
</BODY>
</HTML>
============

Happy programming...

Regards,
gladxml
0
 
LVL 1

Expert Comment

by:JennyRo
ID: 8083196
Thank-you gladxml

It all becomes clear to me now

As soon as I get some points they're yours

Jenny
0
 

Author Comment

by:keyan
ID: 8135708
Thanks to everybody , you help me very much, Br Key
0
 
LVL 15

Expert Comment

by:gladxml
ID: 8140828
keyan,

Does my first comment does not answer your question? Cause the code that I had posted has been tested and work fine here with me... What is the problem with the code...

I just want to know if you did test the code that I had posted...
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question