LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 02-16-2008, 03:46 PM   #1
kshkid
Member
 
Registered: Dec 2005
Distribution: RHEL3, FC3
Posts: 383

Rep: Reputation: 30
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
 
Old 02-16-2008, 04:22 PM   #2
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Wheezy/Jessie/Sid, Linux Mint DE
Posts: 4,235

Rep: Reputation: 545Reputation: 545Reputation: 545Reputation: 545Reputation: 545Reputation: 545
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
 
Old 02-16-2008, 10:20 PM   #3
kshkid
Member
 
Registered: Dec 2005
Distribution: RHEL3, FC3
Posts: 383

Original Poster
Rep: Reputation: 30
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
 
Old 02-16-2008, 10:25 PM   #4
kshkid
Member
 
Registered: Dec 2005
Distribution: RHEL3, FC3
Posts: 383

Original Poster
Rep: Reputation: 30
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
 
Old 02-16-2008, 11:06 PM   #5
arijit_2404
Member
 
Registered: Jul 2007
Location: Kolkata, India
Distribution: Fedora 9
Posts: 85

Rep: Reputation: 15
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
 
Old 02-17-2008, 05:20 AM   #6
kshkid
Member
 
Registered: Dec 2005
Distribution: RHEL3, FC3
Posts: 383

Original Poster
Rep: Reputation: 30
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
 
Old 02-17-2008, 09:03 AM   #7
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Wheezy/Jessie/Sid, Linux Mint DE
Posts: 4,235

Rep: Reputation: 545Reputation: 545Reputation: 545Reputation: 545Reputation: 545Reputation: 545
Quote:
Originally Posted by kshkid View Post
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
 
  


Reply

Tags
ajax


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
perl CGI + dynamic table generation kurrupt Programming 8 09-27-2006 11:25 PM
LXer: Sql - stored procedures, views, and dynamic sql generation LXer Syndicated Linux News 0 08-17-2006 07:33 AM
PHP: referencing form elements with dynamic names Locura Programming 5 03-18-2004 11:24 AM
drop down box / new selection gmarais Programming 4 03-08-2004 03:57 AM
PERL: populating a drop down box from the DB vous Programming 3 08-27-2003 08:41 AM


All times are GMT -5. The time now is 09:38 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration