1
laden0868
auto populating select boxes for submit form..
  • 2010/12/1 18:31

  • laden0868

  • Just popping in

  • Posts: 8

  • Since: 2010/9/8 1


Greeting to all , i want to use a jquery ajax plugin: "auto populating select boxes" for a submit form of the mxdirectory modules.

i have upload the sql file and test it on the server out of xoops, it works correctly!

then i try to make this works on xoops,

1. i have place those html code to the modules html file,

2. upload the sql file that the plugin provided to xoops modules prefix.

3. in the templates theme.html, i have include the jquery.js and the select-chain.js file in the header

4.the select-chain.php file i have place it to root, theme templates, modules root , modules templates directory..
(because i don't know the script "url:select-chain.php" means where)

i have edited the php file but not working...

here r the orignal php code, like this:
Quote:
<?php

if (@$_REQUEST['ajax']) {

// connect to local database 'test' on localhost

$link = mysql_connect('localhost', 'root', '');

if ($link == false) trigger_error('Connect failed - ' . mysql_error(), E_USER_ERROR);
$connected = mysql_select_db('test', $link); if ($connected) { $results = mysql_query('select * from test.select_chain where category="' . strtolower(mysql_real_escape_string(strip_tags($_REQUEST['category']))) . '"');

$json = array(); while (is_resource($results) && $row = mysql_fetch_object($results)) {
$json[] = '"' . $row->label . '"'; }

echo '[' . implode(',', $json) . ']'; die(); // filthy exit, but does fine for our example. }
else
{ user_error("Failed to select the database"); } }

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>Select Chain</title>
<style type="text/css" media="screen">
<!--
BODY { margin: 10px; padding: 0; font: 1em "Trebuchet MS", verdana, arial, sans-serif; }
BODY { font-size: 100%; }
H1 { margin-bottom: 2px; font-family: Garamond, "Times New Roman", Times, Serif;}
DIV.selHolder { float: left; border: 3px solid #ccc; margin: 10px; padding: 5px;}
TEXTAREA { width: 80%;}
FIELDSET { border: 1px solid #ccc; padding: 1em; margin: 0; }
LEGEND { color: #ccc; font-size: 120%; }
INPUT, TEXTAREA { font-family: Arial, verdana; font-size: 125%; padding: 7px; border: 1px solid #999; }
LABEL { display: block; margin-top: 10px; }
IMG { margin: 5px; }
SELECT { margin: 10px; width: 200px; }
-->
</style>

<script src="/js/jquery.js" type="text/javascript"></script>
<script src="select-chain.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
<!--
$(function () {
var cat = $('#categorySelect');
var el = $('#elementSelect');
var attr = $('#attributeSelect');

el.selectChain({
target: attr,
url: 'select-chain.php',
data: { ajax: true, anotherval: "anotherAction" }
});

// note that we're assigning in reverse order
// to allow the chaining change trigger to work
cat.selectChain({
target: el,
url: 'select-chain.php',
data: { ajax: true }
}).trigger('change');

});
//-->
</script>
</head>
<body id="page">
<div id="doc">
<h1>Select Chain</h1>
<div class="selHolder">
<h2>Element Category</h2>
<select id="categorySelect" name="category" size="5">
<option>Forms</option>
<option>Scripts</option>
</select>
</div>
<div class="selHolder">
<h2>Element</h2>
<select id="elementSelect" name="category" size="5">
<option>[none selected]</option>
</select>
</div>
<div class="selHolder">
<h2>Attributes</h2>
<select id="attributeSelect" name="category" size="5">
<option>[none selected]</option>
</select>
</div>
</div>
</body>
</html>



and i have edited the php file to this:

Quote:

<?php

if (@$_REQUEST['ajax']) {

global $xoopsDB;

$results=$xoopsDB->query('select * from x620_xdir_select_chain where category="' . strtolower(mysql_real_escape_string(strip_tags($_REQUEST['category']))) . '"');

$json = array(); while (is_resource($results) && $row = $xoopsDB->fetch_object($results)) {

$json[] = '"' . $row->label . '"'; } echo '[' . implode(',', $json) . ']'; die();
}

?>


i have copy a part of html code to modules index.html file..

Quote:
<select id="categorySelect" name="category" size="5"> <option>Forms</option> <option>Scripts</option> </select>

<select id="elementSelect" name="category" size="5"> <option>[none selected]</option> </select>

<select id="attributeSelect" name="category" size="5"> <option>[none selected]</option> </select>



i have include the jquery script and the plugin script on the header of the theme.html, like this:
Quote:

<script type="text/javascript">

$(function ()
{ var cat = $('#categorySelect');
var el = $('#elementSelect');
var attr = $('#attributeSelect');
el.selectChain({ target: attr, url: 'select-chain.php', data: { ajax: true, anotherval: "anotherAction" } });

// note that we're assigning in reverse order
// to allow the chaining change trigger to work

cat.selectChain({ target: el, url: 'select-chain.php', data: { ajax: true } }).trigger('change'); });

</script>



i have place this php file in the root , theme, modules, modules theme directory....

coz i don't know the script file " url: " means where.....

by the way i don't know how to correct those php code to connect the xoops database correctly..

in fect i m not a coder...haha

sorry for my poor english..

and thx for helping!


2
laden0868
I want to use this ajax jquery plugin for a submit form, but don't know how to connect xoops..
  • 2010/12/2 7:04

  • laden0868

  • Just popping in

  • Posts: 8

  • Since: 2010/9/8 1


Greeting to all , i want to use a jquery ajax plugin: "auto populating select boxes" for a submit form of the mxdirectory modules.

i have a topic on this thread

i m a beginner of xoops, and i m not a coder anyway..

that plugin have a php file that let us to connect the database,
the code is :
Quote:

if (@$_REQUEST['ajax']) {

// connect to local database 'test' on localhost

$link = mysql_connect('localhost', 'root', '');

if ($link == false) trigger_error('Connect failed - ' . mysql_error(), E_USER_ERROR);
$connected = mysql_select_db('test', $link); if ($connected) { $results = mysql_query('select * from test.select_chain where category="' . strtolower(mysql_real_escape_string(strip_tags($_REQUEST['category']))) . '"');

$json = array(); while (is_resource($results) && $row = mysql_fetch_object($results)) {
$json[] = '"' . $row->label . '"'; }

echo '[' . implode(',', $json) . ']'; die(); // filthy exit, but does fine for our example. }
else
{ user_error("Failed to select the database"); } }

?>




i have try to edit those code to this but not working..


Quote:

<?php

if (@$_REQUEST['ajax']) {

global $xoopsDB;

$results=$xoopsDB->query('select * from x620_xdir_select_chain where category="' . strtolower(mysql_real_escape_string(strip_tags($_REQUEST['category']))) . '"');

$json = array(); while (is_resource($results) && $row = $xoopsDB->fetch_object($results)) {

$json[] = '"' . $row->label . '"'; } echo '[' . implode(',', $json) . ']'; die();
}

?>



can anyone tell me how to connect the database correctly,
or is that xoops need to install some plugin for json and else??

thank you very much, and sorry to my poor english.....

3
ghia
Re: auto populating select boxes for submit form..
  • 2010/12/2 9:38

  • ghia

  • Community Support Member

  • Posts: 4953

  • Since: 2008/7/3 1


No use to open a new thread.
Keep your problem together.

Login

Who's Online

119 user(s) are online (70 user(s) are browsing Support Forums)


Members: 0


Guests: 119


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Apr 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits