File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes refresh variables after changing select option Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "refresh variables after changing select option" Watch "refresh variables after changing select option" New topic
Author

refresh variables after changing select option

Irina Ivanova
Greenhorn

Joined: May 22, 2012
Posts: 2
I have a select with many options and I have an input text field that should depend on select option. So when I choose some option the next input field in the form should be changed.

Here is the select code:


and here is the text input code:


But in the select tag there is missing onChange value, because I don't know, how to do that
Almost all solutions that I could find are in PHP, but I do not have possability use PHP. Also solution with specifing the page URL is not suitable, becouse this is not just page, but browser extension.

Can somebody help with this JavaScript function?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61201
    
  66

First of all, don't use document.write(). Not only is it a dinosaur, it will replace the current page with the HTML you specify. Clearly, not what you want.

But in the select tag there is missing onChange value, because I don't know, how to do that

The easiest way (but not the best -- but let's take it slow for now) is to create a JavaScript function, and to call it in the onchange attribute:

and


Almost all solutions that I could find are in PHP

PHP is useless as it's a server-side technology and you need client-side code. So JavaScript is the right way to go. Likely, those examples are old -- from before JavaScript became capable enough, and we had to make a server round trip to make any changes to the page. Luckily, those days are long gone.

You should give the input element an id value, and then you can change its value with:

That should get you started.

It sounds like you are very new to JavaScript. You should get a good tutorial or book (make sure it's modern) to make sure you understand the basics.

Once you understand the basics, then you can start using a library like jQuery that makes all of this much easier.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Irina Ivanova
Greenhorn

Joined: May 22, 2012
Posts: 2
Thank You very much! Your advices were very helpful, now it works.

The code is now looking like this:
The select element:


The JS function:


And the input field is just input field.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: refresh variables after changing select option