LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   drop down box elements - dynamic generation (https://www.linuxquestions.org/questions/programming-9/drop-down-box-elements-dynamic-generation-621656/)

kshkid 02-16-2008 02:46 PM

drop down box elements - dynamic generation
 
hello all,

I could not find similar problem by searching in the forum

Could you please help me with this ?

I have a html page. Only when the user clicks on the drop - down box,
the list should be populated - something like dynamic drop down box elements generation.

I am trying to accomplish this with perl + CGI

Instead of using a html page, I can make use of a perl CGI script directly to populate the values on the run,
but I would like to do something like first to start with a html page, from there when there is onClick action on the drop down box, a perl script should be triggered and then a new html page to be rendered with values in the drop down box.

Could you please provide some pointers for that ?

Thanks

jlinkels 02-16-2008 03:22 PM

If you have a server based script, you have to submit a form with some information, build the list on the server, and send it back to your client. You can not do it without re-loading the page and telling the server something on which it can decide how to build the list.

Alternatively you could build the list client-based usung javascript. Some good tools here

jlinkels

kshkid 02-16-2008 09:20 PM

yes thats a server based script

Can I bind some action on the click of a drop down box ?

In a form, an action is explicitly binded to a submit button, can I do something similar to that ?

If I could do that, once the click action is sensed, dynamic list can be generated with a script and then the page reloaded

kshkid 02-16-2008 09:25 PM

Or is it possible to do it this way ?

When a html page gets loaded, is it possible to execute some script in background so that drop down list can be dynamically generated without the user having to click the drop down list and then generate ?

Am not sure whether this is possible or not.

Thanks much in advance

arijit_2404 02-16-2008 10:06 PM

Ajax technology can be used to do this. I've used to communicate with server-side Java-servlet, also know that .php can be used in server-side code. But no so sure about cgi-perl.

On HTML page's <body onLoad="someJavascriptMethod()"> is called.

In that Javascript method, call the server-side script. Server-script returns the elements of dropdown-box as string. Like,
in java, String s = "<option value='a'>a</option>" + "<option value='b'>b</option>" and returns this String.

When Ajax call return from server-side script, an user-implemented callback method is invoked and in that method, dynamically update the HTML page.

Here's a link to Servlet implementation;
Link1

kshkid 02-17-2008 04:20 AM

thanks for the reply.

I don't know much about these technologies. I had heard of them only conceptually.

This is what I had tried.

Instead of rendering a html page, I triggered cgi script to do that

something like the below

using cgi script to do that
Code:

http://url/output.cgi
instead of using a html page
Code:

http://url/some.html
#################

this gives me another potential problem

Example:

cgi script generates the html file and displays ( output.cgi )
the form in the html page is something like
Code:

<form action="output.cgi" method="POST">
  <select>
  ..
  </select>
  <input type="submit" value="Goo">
  </form>

one item is selected from the drop down listing
since the same cgi script is called which is output.cgi

I have the statement in output.cgi something like
Code:

use CGI;
my $cgi = CGI->new();
print $cgi->header('text/html');

The parameter values are overridden and am unable to use them anymore
Selection values are gone.

Could you please provide some pointers to overcome this ?

Thank you very much

jlinkels 02-17-2008 08:03 AM

Quote:

Originally Posted by kshkid (Post 3059829)
yes thats a server based script

Can I bind some action on the click of a drop down box ?

In a form, an action is explicitly binded to a submit button, can I do something similar to that ?

If I could do that, once the click action is sensed, dynamic list can be generated with a script and then the page reloaded

That is very easy. You have to attach the submit action to the OnChange event of the drop down box. Like in this example:

Code:

onclick="this.form.submit()"
You could also attach actions to OnFocus or OnBlur events. Additionally you can change or add fields to your form before submitting so the server knows the status of the form when it receives the request. Search for "changing DOM object javascript" in Google.

I have built some rather large webpages based on this technology, but I have to warn you, those were for an Intranet application. If you do this for an Internet application waiting times may become tedious for the user.

AJAX could also be an option, a very nice implementation indeed without page refreshes, but you have to rely heavily on JavaScript and DOM, and the user would have to suffer response times as well if the connection is below a few mbit.

Last but not least, I have no experience with cgi and I don't know how powerful it is. But in PHP it is fairly easy to create select boxes on the server site, handle form input from posted data etc.

Sorry that I cannot reply to your latest post in detail, I do not completely understand what you tried to explain, but that is my fault.

jlinkels

jlinkels


All times are GMT -5. The time now is 10:34 AM.