Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Dynamic content w/o refresh

by wackattack (Sexton)
on Sep 13, 2005 at 20:33 UTC ( [id://491686]=perlquestion: print w/replies, xml ) Need Help??

wackattack has asked for the wisdom of the Perl Monks concerning the following question:

I want to add dropdown boxes to a webpage. The only problem is that each dropdown box depends on the selection of the previous dropdown box. Can I do this dynamically without refreshing the webpage?

For instance, somebody selects which database they want to view. Then when that is selected another dropdown box becomes activated and they can select which nodes in that database to look at. The choices from the second dropdown box are dependent on the first. All of the choices can be programed statically in HTML if it's possible to do this in HTML. However, I don't know if HTML can do this or if I need perl.


Maybe this is a bad place to post this question but you guys have been so helpful in the past.

Thanks,

wacki

Replies are listed 'Best First'.
Re: Dynamic content w/o refresh
by socketdave (Curate) on Sep 13, 2005 at 20:38 UTC
    Javascript is going to be your best bet for this, and is outside the scope of this site. Check out this site for more information on js: http://www.w3schools.com/js/js_intro.asp

    Update:  I just tried out the module that CountZero mentioned. It's very slick and worth a look, especially if you have something complex to do and are already pretty familiar with Perl.

      It is also worth to check out the concept of XML Island. Basically data needed for your HTML page comes as a block of XML (within the same HTML file).

      Java Script has basic DOM support and that's how you get data from your XML island. In this case, the configuration of those dropdown just comes as data.

Re: Dynamic content w/o refresh
by CountZero (Bishop) on Sep 13, 2005 at 21:02 UTC
    To link your Java code to Perl code and data on your server, CGI::Perljax seems to fit the bill.

    CountZero

    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

Re: Dynamic content w/o refresh
by InfiniteSilence (Curate) on Sep 13, 2005 at 21:03 UTC
    Yeah, you're right, the solution you want is JavaScript. Below is a really crude example (for a better one, go here):
    <HTML> <HEAD> <SCRIPT LANGUAGE="JAVASCRIPT"> <!-- function showIt(){alert('hello');} function alterFoob2(){ var theLength = document.forms[0].elements[1].length; document.forms[0].elements[1].options[theLength] = new Optio +n('NewThing', 'NewThing');} //--> </SCRIPT> </HEAD> <BODY> <form name="mainform"> <select name="foob" onChange="alterFoob2()"> <option name="1" />Hi <option name="2" />There </select> <select name="otherfoob"> <option name="3">You <option name="4">Foob </select> </form> </BODY> </HTML>

    The problem with the above is it gets 'too' static. For example, if you need to use different options in your lists you will have to either change your script code (yuck) or, better, try using the CGI module (see the perldoc and scroll down a lot until you get to the JAVASCRIPT section!)

    Update: For those who think the above was a dumb question (and that people like me are idiots for assisting), I'll direct you to the 3rd State of the Onion:  But in my defense, allow me to point out that I'm running the animation by piping commands to RasMol from a Perl script. And that's as it should be. We don't have to do everything with Perl. We just have to be in control.

    Celebrate Intellectual Diversity

Re: Dynamic content w/o refresh
by rlb3 (Deacon) on Sep 13, 2005 at 21:17 UTC
Re: Dynamic content w/o refresh
by Anonymous Monk on Sep 13, 2005 at 22:33 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://491686]
Approved by kirbyk
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (7)
As of 2024-03-29 11:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found