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 How to insert at runtime using AJAX Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "How to insert at runtime using AJAX" Watch "How to insert at runtime using AJAX" New topic
Author

How to insert at runtime using AJAX

Saurabh Naik
Ranch Hand

Joined: Apr 24, 2008
Posts: 87
suppose I have combobox of Countries.. and second combo box of Cities.. ..
when I select Country the Cities get displayed according to it !! My program is running fine..
but when I select country from one combo box the second combo box appears at that time ... I have written code on onchange() event !

my problem is.. two combo box must appear on page..and when I select country from one combo box.. the second combo box should be filled..

so how to overcome this difficulty ?

I have written code in JSP (<select><option></option></select>) and in html I have used div tag to insert combo box at runtime..

I have to write that code in my main html and not in jsp..and want to just insert the data on onchange event !

my another problem is .. when I use document.myform.getElementById("cities").. this code does not work

and documen.getElementById("cities") this works perfectlyy

Thanks in Advance

SCJP 6 (88%), SCWCD 5 (78%), preparing for SCBCD
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61756
    
  67

Saurabh Naik wrote: suppose I have combobox of Countries..
Firstly, please be sure to use proper terms to avoid confusion. There is no such thing as a "Combo Box" in HTML. Please read this for more information.

Secondly, I'm not sure exactly what you are asking. Are you having trouble creating an empty second select element to be filled in later?

And,
my another problem is .. when I use document.myform.getElementById("cities").. this code does not work

Of course not. The form has no such method. Why would you think it would?

and documen.getElementById("cities") this works perfectlyy

Really? "documen"? Please be careful when posting code to the forums that it does not contain mistakes like this.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Steve James
Ranch Hand

Joined: Apr 12, 2009
Posts: 44
// The function which will get called on onchange





I am just a brick in the wall of Java
Saurabh Naik
Ranch Hand

Joined: Apr 24, 2008
Posts: 87
I am sorry for my mistakes.

and document.myform.mydiv.value .. does not work... div tag doesn't have attribute called name.

I am inserting div tag in the select tag ... <select><div id="mydiv"></div></select>

and in JSP I am writing <option> tags.. but it is not working.....

but if I write in JSP <select> and <option> tag it works perfectly... but it occurs on html on onchange event...

so how to solve this problem
Steve James
Ranch Hand

Joined: Apr 12, 2009
Posts: 44
I am inserting div tag in the select tag ... <select><div id="mydiv"></div></select>


just guessing div visible and hidden problems ?

Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
You really should not be using document.myForm.getElementById. You should just use document.getElementById().

When you say it does not work, are you getting an error message? Have you used a tool such as Firebug or Web Developer Toolbar to look at the source code after it runs?

Eric
Saurabh Naik
Ranch Hand

Joined: Apr 24, 2008
Posts: 87
No its not giving me any kind of error messege. I am not using any kind of tool for doing it !

and even I am thinking that div tag get hide in select tag. thats why its not showing ...

It runs with document.getElementById() method.. but again If I use directly div tag without select tag in html file it runs fine

but if I use select tag in html file and in that div tag.. so I can give opting tag through calling function.. it does not work.

any solution ?

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to insert at runtime using AJAX