hi all,
i'm newbie in perl.i have face problem how to add function ajax
(onchange) on my file.
this is my code...
$ajx_ctrl = $query->param('ajx_ctrl');
$co_id = $query -> param('select_co');
my $exported_fx = sub {
my $searchterm = shift;
my $sql = qq< select file_name from file_name where id_module = ? >;
my $dbh_label = $dbh_label;
my $sth = $dbh_label->prepare( $sql );
$sth->execute( $searchterm . '%' );
my $html1 = "";
$html1 = qq!<select name="file_name" id="id_module" $input_style >
#OnChange="details( ['users'],['ddiv'] ); return true;">\n!;
my $firstrow = $sth->fetch();
if ( defined $firstrow ) {
$html1 .= qq!<option >! .qq!- Select One -! . qq!</option>\n!;
$html1.= qq!<option>! . $firstrow->[0] . qq!</option>\n!;
# dot on each option from the db
while ( my $row = $sth->fetch() ) {
$html1.= qq!<option>! . $row->[0] . qq!</option>\n!;
}
}
else
{$html1 .= qq!<option >! .qq!- Select One -! . qq!</option>\n!;}
# close off the select and return
$html1 .= qq!</select>\n!;
#&common_error("$html1");
return($html1);
};
my $dbh_label = $dbh_label;
$file_base .=qq~ <select name="file_name" $input_style>
<option>- Select One -</option>
</select>
~;
my $exported_form = sub {
my $searchterm2 = shift;
my $sql2 = qq< select form_action from form where id_file = ? >;
my $dbh_label = $dbh_label;
my $sth2 = $dbh_label->prepare( $sql2 );
$sth2->execute( $searchterm2 . '%' );
my $html2 = "";
$html2 = qq!<select name="form_action" id="id_file" $input_style >
#OnChange="details( ['users'],['ddiv'] ); return true;">\n!;
my $firstrow2 = $sth2->fetch();
if ( defined $firstrow2 ) {
$html2 .= qq!<option >! .qq!- Select One -! . qq!</option>\n!;
$html2.= qq!<option>! . $firstrow2->[0] . qq!</option>\n!;
# dot on each option from the db
while ( my $row = $sth2->fetch() ) {
$html2.= qq!<option>! . $row->[0] . qq!</option>\n!;
}
}
else
{$html2 .= qq!<option >! .qq!- Select One -! . qq!</option>\n!;}
# close off the select and return
$html2 .= qq!</select>\n!;
return($html2);
};
my $dbh_label = $dbh_label;
$form_base .=qq~ <select name="form_name" $input_style>
<option>- Select One -</option>
</select>
~;
#--- get module ---#
$sql = qq~
SELECT id, module
FROM module
~;
$sth = $dbh_label->prepare($sql);
$sth->execute() or &common_error("SQL","Couldn't execute statement :
$DBI::errstr",1);
$sel_module .=qq~
<option value="">- Select One -</option>
~;
while (($id, $module) = $sth->fetchrow_array())
{
$sel_module .=qq~
<option value="$id" >$module</option>
~;
}
$sth->finish();
#----------------------#
### start add company form ##
my $Show_Form = sub {
my $html = "";
$html .= <<EOT;
<HTML>
<HEAD><title>CGI::Ajax Example</title>
</HEAD>
<BODY>
<form action="setting_label_ajax.cgi" method=post name="mainform">
<input type="hidden" value="Save" name="action">
<input type="hidden" value="2" name="link">
<tr height="20">
<td bgcolor="$table_color"><div name="co_level" id="co_level"><
$table_title> <b>$forwhat</b></font></div></td>
</tr>
<tr>
<td width="729">
<div align="left">
<!-- WE REPLACE THE HIDDEN TABLE ABOVE WITH THIS NEW ONE -->
<table width="100%" border="1" cellpadding="0" cellspacing="0"
style="border-collapse: collapse" bordercolor="#111111"
id="AutoNumber21">
<tr>
<td>
<center>
<table border="0" cellpadding="1" cellspacing="2" style="border-
collapse: collapse" bordercolor="#111111" id="AutoNumber20"
width="90%">
<tr height="8"><td></td></tr>
<tr height="25">
<td width="22%"><$content_style>Module</font></td>
<td width="2%"><$content_style>:</font></td>
<td width="76%" align="left"><select name="module" id="module"
OnChange="search( ['module','NO_CACHE'],['ddiv'] ); return true;"
$input_style>
$sel_module
</select>
</td>
</tr>
<tr height="25">
<td><$content_style>File Name</font></td>
<td><$content_style>:</font></td>
<td>
<div id="ddiv">
<select name="file" id="file_name"
OnChange="search2( ['file_name','NO_CACHE'],['ddiv'] ); return true;"
$input_style>
$file_base
</select>
</div>
</td>
</tr>
<tr height="25">
<td><$content_style>Form</font></td>
<td><$content_style>:</font></td>
<td>
<div id="ddiv">
$form_base
</select>
</div>
</td>
</tr>
<tr height="8"><td colspan="3"></td></tr>
</table>
</td>
</tr>
</table>
<!-- NEW TABLE ENDS HERE -->
<tr><td> </td></tr>
<tr height="20">
<td bgcolor="$table_color"><$table_title><b> Company
Information</b></font></td>
</tr>
<tr>
<td align="left">
<div align="left">
<table width="100%" border="1" cellpadding="0" cellspacing="0"
style="border-collapse: collapse" bordercolor="#111111"
id="AutoNumber21">
<tr>
<td>
<center>
<input type="hidden" name="type" value="$type">
</center>
</td>
</tr>
</table>
</div>
</td>
</tr>
<tr height=8><td></td></tr>
<tr>
<td width="100%">
<p align="right">
<input type="button" name="back" value="Back"
onClick="document.location = 'setting_label.cgi?'" $button_style>
<input type="submit" name="Save" value="Save" $button_style>
</td>
</tr>
</form>
</BODY>
</HTML>
EOT
return($html);
};
my $pjx = CGI::Ajax->new(
search => $exported_fx,
search2 => $exported_form,
);
----------------------------------------------------------------------------------------------------------------------------------------------------
my problem is i want to create 3 dropdown list but 2nd list is based
on 1st list and the 3rd list is based in 2nd list. if we not choose
anything only word -select one- is appear..plz help me...thanks..
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/