Topic: Textfield to appear onclick

How can i make a text field appear when i click and hold some text(the text will be the title of a torrent) and a textfield appears letting me edit the title(but the name of the title will be in textfield not opening an empty field but with the name of the text and i will be able to update it

BTW you might not understand cause i do not know allot of english and i cannot explain it sad

P.S
Mybb forums have this!

Re: Textfield to appear onclick

Hi,

If you use the on click event of the text field to call a registered function the function can get the proper text however you need to and assign it to the value attribute of the text field.

Like:

Code: PHP

<?php

require("xajax/xajax_core/xajax.inc.php");

$xajax = new xajax();

$xajax->registerFunction("myFunction");

$xajax->processRequest();



myFunction($txt)

{

  $resp = new xakaxResponse();

  if ($txt == '')

    $resp->alert ('You did not enter anything...');

  else if ($txt == 'dog')

   $resp->assign(myid', 'value' 'You entered dog');

  else

   $resp->assign('myid', 'value','You entered ' .$txt);

  return $resp;

}

?>

[code html]
<html>
<head>
  <? $xajax->printJavaScript(); />
</head>
<body>

Enter text: <input id="myid" onclick="xajax_myFunction(this.value);">

</body>
[/code]

Last edited by edrobinson (2008-05-17 7:28:45 PM)

If you ever stop learning you may as well dig a hole, crawl in and pull the top over yourself.

Re: Textfield to appear onclick

Hello,
I am tring to use the example from above. I  have a link on my page that will populate a div-(txtCompany) with the company info for that product

1. reads database
2. returns list of products (each product is a link)
3. click on a product
4. reads the company id passed with the click of a link.
5. displays the company info in the div with the id of (txtCompany)

My problem is in step 4 I get an error, xajax_getCompany is not defined
function onclick(event) { xajax_getCompany("0"); }(click clientX=167, clientY=180)

I hope I explained myself well enough.

thank you for your help

Code: PHP

<?

$dbh = mysql_connect( "host", "usr", "pass");

        $bol = mysql_select_db ("dbinventory",$dbh) or die("sad...");



include ('../xajax/xajax_core/xajax.inc.php');

$xajax = new xajax();

$xajax->registerFunction("getCompany");

$xajax->processRequest();



function getCompany($a)

{

    $response = new xajaxResponse();

        $sql1 = "SELECT * FROM `tblproduct` WHERE intID = " . $a;// ORDER BY intOrder ASC";

        $res1 = mysql_query($sql1);

        while ($arr1 = mysql_fetch_array($res1))

            {

            extract($arr1);

            $html = $intID . '

' . $strCompanyName  . 'br /' . $strStreet  . 'br /' . $strCity . 'br /' .  $strState  . 'br /' . $strZip  . 'br /' . $strPhone  . 'br /' . $strFax  . 'br /' . $strCell  . 'br /' . $strEmail;



        }//END WHILE



    $response->assign('txtCompany', 'innerHTML', $html);

    //$response->assign('reset', 'style.display', 'block');

    return $html;

}



?>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">

<html>

<head>

</head>

<body>

<div align="center">



<table border="2" align="center" width="75%" height="85%">

    <tr>

        <td rowspan="2">

<?php

        $sql1 = "SELECT * FROM tblproduct";// ORDER BY intOrder ASC";

        $res1 = mysql_query($sql1);

        while ($arr1 = mysql_fetch_array($res1))

            {

            extract($arr1);

            echo "<a href=\"javascript:void(0)\" onClick=\"xajax_getCompany('0')\">Test Link[Product_ID] this is a test link</a>

' ;

            echo "<a href=\"javascript:void(0)\" onClick=\"xajax_getCompany('" . $arr1['intID']  . "')\">" . $arr1['strProductName'] . '[' . $arr1['intID']  . ']</a>This link grabs infor from database' ;

        }//END WHILE

?>

        </td>



        <td>

            <div id="txtCompany">co info</div>

        </td>

    </tr>

    <tr>

        <td>

            Product discription

        </td>

    </tr>

</table>



</body>



 

Re: Textfield to appear onclick

Your getCompany() procedure is returning $html instead of $resp...

Ed

If you ever stop learning you may as well dig a hole, crawl in and pull the top over yourself.

Re: Textfield to appear onclick

Sorry that didn't work, I am still getting the same error.

I am used to sajax architecture and I want to learn xajax, where can I find a help file for what I am trying to accomplish. This way I can understand the big picture.

Code: PHP

    $response->assign('txtCompany', 'innerHTML', $html);

    //$response->assign('reset', 'style.display', 'block');

    return $response;

Thank you for your help.

Re: Textfield to appear onclick

There is a lot "stuff" here:

http://xajaxproject.org/en/docs-tutorials

You can also get a feel for things by studying the example code that comes with the XAJAX download.

here's a piece of code that does most of what you want. The crux of it is assignning some text to a div' innerHTML attribute:

Code: PHP

<?php

/*

    Write into a div in a table.

*/

require_once("xajax/xajax_core/xajax.inc.php");

$xajax = new xajax();                                                    



function test($dta='')

{

    $resp=new xajaxResponse();    

        /*

            You would do your database query here and

            populate the div with its results...

        */

    $resp->assign('div1','innerHTML', "Query Results...");

    return $resp;

}

//$xajax->setflag('debug', true);  //Uncomment to turn on xajax debugging.

$xajax->register(XAJAX_FUNCTION,"test");

$xajax->processRequest();

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html>

<head>

<? $xajax->printJavascript('xajax'); ?>

<title>test</title>

</head>

<body>

<center>

<table>

<tr><td><div id="div1"></div></rd></tr>

</table>

<br/>

<input type="button" value="Click Me" onclick="xajax_test()"/>

</center>

</body>

</html>

 

You might also turn on the XAJAX debugger ($resp->configure('debug',true);)

Ed

Last edited by edrobinson (2009-09-29 9:23:01 PM)

If you ever stop learning you may as well dig a hole, crawl in and pull the top over yourself.

Re: Textfield to appear onclick

Ed,

I didn't know about the javascript portion of the code.

Code: PHP

<? $xajax->printJavascript('xajax'); ?>

 

It works, now I need to change my query(i know how)!

Thank you!
-James