aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Javascript help needed? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Javascript help needed?" Watch "Javascript help needed?" New topic
Author

Javascript help needed?

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9427
    
    2

Guys,

I'm trying the following javascript and I'm not able to get the question number inside it,

function displaySubchoice(QuestionId){

dabba="document.forms[0]."+QuestionId+".length";
alert("dabba "+dabba);
}

I"m just getting the alert as a String. Instead it should be 2 where my QuestionId is 2. Please any help guys!


SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42280
    
  64
You're enclosing it in double quotes - which means it is interpreted as a string literal. The eval method evaluates a string; something like



Ping & DNS - my free Android networking tools app
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9427
    
    2

Thanks Ulf for the help. I'll explain you the entire scenario that I'm trying to accomplish.

I have a database table which holds some questions and each question has a set of choices (choices table) in a different table and each choice has some subchoices (subchoices table) in another table. Now I have a main table (say lookup table) that simply has the id's of some of the questions that actually exist in the questions table. I'll populate the lookup table through some interface. Now I want to read all the question id's from the lookup table and see in the choies table and display them in the form of radio buttons. Now based on the choice that I select, I'll have to display those corresponding subchoices. Now imagine I have question 1 which has 2 choices and I select the first choice and it in turn has 2 subchoices and now I select the first subchoices and for this combination, I know that I should be taken to question3 as I would have stored it already in the subchoice table. Teh logic goes on and on till I finish displaying all the questions from the logic table. How can I implement such a logic. I can't use AJAX as the system that I'm working on is relatively old.

Please help required.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42280
    
  64
Yes, you want to access form elements whose names you don't know in advance. So you create their names dynamically, as your code does already. My post showed you how to make that work correctly. So I'm not sure what you're asking?
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9427
    
    2

Not exactly Ulf....You are right that I'm creating the names dynamically and based on the choices that I select, I will show/hide the subchoices and next question. Is there a way to accomplish this?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42280
    
  64
Sounds like using a bit of CSS -particularly "display:block" and "display:none", which you can change using JavaScript- should do the trick.
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9427
    
    2

Ulf,

I tried using display:none but since I'm involved with a lot of such hide/display logic, I'm not able to accomplish my task effectively. I want to try out much cleaner solution to this...AJAX. Do you know any source where I can get some samples that explains how we can send AJAX requests to a servlet which in turn talks to the database and send the response to the browser?
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9427
    
    2

Ulf,

Can you please help me on how I can accomplish this using AJAX.
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9427
    
    2

Do we really have to use some AJAX libraries or some Toolkits to accomplish my task at hand? I'm just considering AJAX for this one problem. So what would be the best deal for me guys!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Javascript help needed?