Forum Moderators: coopster & phranque

Message Too Old, No Replies

perl .cgi with javascript

trying to onclick for variable

         

henry214

3:55 pm on Sep 1, 2005 (gmt 0)

10+ Year Member



Hello,
I am trying to get a word to become a variable using javascript and then jump to a subroutine to use that selected word. I am having problems with Sumbiting the variable for use in subroutine.
Here is what I have.

$select=$query->param('Select');
$submit=$query->param('Submit');

if ($select ne "") {
&view;
}
else {
&showdir;
}

sub showdir {
...
.... code stuff
.....
......function for javascript

</head>

<script language="JavaScript">

function lookup (tform,DEVICE) {
tform.Select.value = DEVICE;
tform.Sumbit;
return false;
}
</script>

.. stuff collecting text in arrays @c1 @c2 thru @c10
.. printing out in 5 col table
...

print "<input type=\"hidden\" name=\"Select\" value=\"\">";

#eventually I want to place the below print in a
#foreach loop to print out each $_ of arrays
#@c1 thru @c10

print "<a href=# onclick=\"return lookup(pr_mngr,'DEVICE');\">DEVICE</a>";

print "<table border=\"0\" width=\"100%\">\n";
print "<tr>\n";
...
...
....
...
}#close sub

sub view {

trying to get variable in here to use for other coding purpose.

}#close sub

Moby_Dim

6:31 am on Sep 2, 2005 (gmt 0)

10+ Year Member



Your sub view should take this variable to process from the hash of form processing procedure : 1) you choose a word in the list (javascript) and submit the form (form's "action" is empty or contains the same script) - thus you send this value to the same script forcing the script to process this variable; 2) process input (form parsing procedure) and send this variable to the procedure, if this variable is found in the hash after form processing.

henry214

2:29 pm on Sep 2, 2005 (gmt 0)

10+ Year Member



I am not sure where to place the tform.Submit.
I have it in the function, but it does nothing as is.
"but I get no errors"

should it be in here somehow
print "<a href=# onclick=\"return lookup(pr_mngr,'DEVICE');\">DEVICE</a>";
if so, how do I place it here?

thanks for your help..

Moby_Dim

4:24 pm on Sep 2, 2005 (gmt 0)

10+ Year Member



I have not seen your script but i want to tell you the general principle(s).

You have a script. When you launch it, the server produces some response in a form of webpage (dynamic). This page contains a few HTML elements with some blah-blah-blah..., along with the form (or a few forms), of course. Any form contains some options to select from (select box, or checkboxes, or radio buttons,...) ot a simple text field(s) you can enter any word(s). Submit button as well (or you may use .sibmit() method).

When you push this button (or use .submit() method) you send some value(s) to the script (the name should be in &lt;form action="url_of_some_script.cgi"...&gt; ; if action is empty, this means the same script will be used).

So, the script must be able to process the own request (form variables).

You must have a procedure to process'em. E.g. sub parse_form {...} (there are a lot of, but all are the same in general).

Somewhere in the beginning of the script you place something like this :
#!shebang
my(%form_hash) = &parse_form();
if($form_hash{'select'}) {
do something with this value
}

...the rest of the code
...
sub parse_form {
...code
}
...
1;

As for the function call to trigger .submit() method, you may place it in any appropriate event handler of form element you use to choose the value. E.g. &lt;select .... onclick="lookup(this.value)"...&gt;