Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Javascript help needed?

 
Joe Harry
Ranch Hand
Posts: 10123
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're enclosing it in double quotes - which means it is interpreted as a string literal. The eval method evaluates a string; something like

 
Joe Harry
Ranch Hand
Posts: 10123
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10123
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10123
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10123
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf,

Can you please help me on how I can accomplish this using AJAX.
 
Joe Harry
Ranch Hand
Posts: 10123
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic