[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 609
  • Last Modified:

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

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
keyan
Asked:
keyan
  • 8
  • 3
  • 2
  • +1
1 Solution
 
gladxmlCommented:
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
 
gladxmlCommented:

<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
 
gladxmlCommented:
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
JennyRoCommented:
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
 
apolloisCommented:
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
 
gladxmlCommented:
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
 
gladxmlCommented:
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
 
keyanAuthor Commented:
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
 
apolloisCommented:
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
 
JennyRoCommented:
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
 
gladxmlCommented:
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
 
gladxmlCommented:
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
 
JennyRoCommented:
Thank-you gladxml

It all becomes clear to me now

As soon as I get some points they're yours

Jenny
0
 
keyanAuthor Commented:
Thanks to everybody , you help me very much, Br Key
0
 
gladxmlCommented:
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

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 8
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now