jsp doubts....
i have a menu with multiple entries, where only one entry can be selected at a time. i want the page to be redirected to different pages as per the selection of the entry. that is, different pages should be redirected with different entry selections. how to do dat??
Replies
-
Anoop KumarI suppose you are using combox to populate date and then selecting it.
Initially on page load do not select anything then add following like this
you can send pass parameter also.
then in yourFunction() javascript: add how to redirect a page using javascript? - Javascript
You can use Location href Property -
lovejeethey thanks for the reply, but you didn't got the question i guess. sorry if was a bit ambiguous.
it's for combo box only, where there are several entities, say x, y and z. what i want is that when user selects x, it should redirect to another page say abc.jsp, for y, it should redirect to pqr.jsp and so on.... -
Anoop Kumarwhat are xyz....
if these are radio buttons then just use OnClick() event and call the javascript function. -
lovejeetxyz are different entities like anchor1, anchor2 in your example. n ya, onclick() method is a nice solution to that....
-
PraveenKumar PurushothamanWait... Lemme say... You got a combobox with values Page 1, Page 2, Page 3. And upon selecting them, they should redirect you to One.jsp, Two.jsp, and Three.jsp accordingly. If this is the case, you can try this:
-
lovejeethey thanks a lot #-Link-Snipped-#. yup done. now the next problem is the drop down menu's. i want my 3rd dropdown menu to be based on the values of my 2nd menu, and dat to be dependent on the 1st one. how to do that now???
-
PraveenKumar Purushothaman
So it means 3 individual dropdowns huh???lovejeethey thanks a lot #-Link-Snipped-#. yup done. now the next problem is the drop down menu's. i want my 3rd dropdown menu to be based on the values of my 2nd menu, and dat to be dependent on the 1st one. how to do that now??? -
PraveenKumar PurushothamanYou mean like this? The value of the next combo box is dependent on the previous one???
-
lovejeetyup. like this. it includes dynamic selection for some dropdown menu's using database too. 😕
-
PraveenKumar Purushothaman
I guess its getting complicated... Then you got two choices:lovejeetyup. like this. it includes dynamic selection for some dropdown menu's using database too. 😕
1. Ajax Update
2. Page Refresh
Which one do you prefer? -
lovejeeti do not prefer ajax. wanna keep it as the last option. i tried it for two drop down menu's and it wasn't much tought. but when it comes to more than two and when retrieving the values from database, its all over my head....😛
-
PraveenKumar PurushothamanIf you were using ASP.net, it is damn easy... Check this out: #-Link-Snipped-#
-
PraveenKumar PurushothamanAnd I saw this in StackOverflow. Seems promising. Read on...
You need to download JQuery (JavaScript framework) and include that in the head section of the HTML.
Inside the OnChange function for first dropdown call the function to populate the subsequent dropdowns.
The function is a s follows:$(document).ready(function()Â {
    $('#DDIdParent').change(function() {
        populateChildDropdown('DDIdParent');
    });
});
Inside your Servlet's doGet method, you will have a code like this to get the value of subsequent dropdown from the database as a JSON String:function populateChildDropdown(ddId) {
    var dd = $('#' + ddId);
    $.getJSON('json/mapping?dd=' + ddId, function(opts) {
        $('>option', dd).remove(); // Clear old options first.
        if (opts) {
            $.each(opts, function(key, value) {
                dd.append($('').val(key).text(value));
            });
        } else {
            dd.append($('').text("Please select the parent DD"));
        }
    });
}
You need to map the json/mapping to your servlet inside web.xml. You can also pass parameters from the jquery function if needed.        Map options = yourDao.callDatabase(parameter);
        String json = new Gson().toJson(options);
        res.setContentType("application/json");
        res.setCharacterEncoding("UTF-8");
        res.getWriter().write(json); -
lovejeetsir ji i want that in jsp, no php or .net allowed...😔
-
Anoop KumarWithout ajax you need to refresh the page.
using onChange() even submit the page with some flag. and on sevlet/ jsp, you are using, get all the values. now fetch values for next drop down menu on basis of latest dropdown menu. and come back to the page with all values. and populate the your latest dropdown menu and set all the previous values.
why not Ajax. you are just fetching data from database.😀 -
PraveenKumar Purushothaman
Sir Ji! It is JSP! 😀lovejeetsir ji i want that in jsp, no php or .net allowed...😔
And if you really know JavaScript, those things inside PHP block are JavaScripts. No where I have used PHP! Lolz... -
Prasad AjinkyaThis smells like an assignment 😀
But perhaps you need to do this via simply Javascript. -
lovejeet@praveen- oops..... sorry that was a bit confusing by that header of 'php'. will try the code.
@kidakaka- hahaha.......yup, a part of my project only, but what all i could try was for two menu's and that to without the database. rest i need to take the help...😀 -
Prasad AjinkyaHere's what you do -
Declare a javascript array for the URLs.
In the dropdown, the values of each option should map to the index of this URL array.
When the form is submitted, simply invoke a function which will take the value of the dropdown, retrieve the particular URL from that value and change the location to that. -
PraveenKumar Purushothaman
Even then it becomes an AJAX Call right?kidakakaHere's what you do -
Declare a javascript array for the URLs.
In the dropdown, the values of each option should map to the index of this URL array.
When the form is submitted, simply invoke a function which will take the value of the dropdown, retrieve the particular URL from that value and change the location to that. -
Prasad AjinkyaNope. Its still Javascript. Why go into the trouble of AJAX?
You are reading an archived discussion.
Related Posts
Hello evaryone,my name is supradeep. Im from hyderabad doing my Ist year BTECH in ELECTRICAL AND ELECTRONICS ENGINEERING . Am intrested in doing MBA at IIM and ii also have...
Civil Engineering constructions, I should rather say marvels, have always stunned me by their creation. Now nature has done the same.
Here, have a look at the 13 most awesome...
guys, i am writing the IES(mechanical) this year
i think many from this forum would also be writing
Experienced people please guide us on what to prepare and how to...
Hello Engineers,
i am anurag....doin engineering.....currently in ma T.E.....i will post my problems soon...
1 more thing,u mite face a little difficulties reading ma short lil languages...bt no worries,as v...
hi all
i wanted to know what a shift register is , its functions and its applications