<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>SaCaWeb</title>
	<atom:link href="http://www.sacaweb.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sacaweb.com</link>
	<description>Soluzioni a problemi quotidiani di programmazione Php, javascript, jQuery, CSS, Actionscript 3, Flash CS3, Photoshop, Java, Java 2EE, JavaBeans</description>
	<lastBuildDate>Wed, 11 Apr 2012 08:59:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Errore Joomla No input file specified</title>
		<link>http://www.sacaweb.com/php-mysql/errore-joomla-no-input-file-specified/</link>
		<comments>http://www.sacaweb.com/php-mysql/errore-joomla-no-input-file-specified/#comments</comments>
		<pubDate>Wed, 11 Apr 2012 08:18:25 +0000</pubDate>
		<dc:creator>sacaweb</dc:creator>
				<category><![CDATA[Php/MySQL]]></category>
		<category><![CDATA[htaccess]]></category>
		<category><![CDATA[joomla SEO]]></category>
		<category><![CDATA[mod_rewrite]]></category>
		<category><![CDATA[NO INPUT FILE SPECIFIED]]></category>

		<guid isPermaLink="false">http://www.sacaweb.com/?p=325</guid>
		<description><![CDATA[L&#8217;utilizzo delle impostazioni SEO/SEF in Joomla può generare qualche problema su alcuni hosting non configurati correttamente (versione di php obsoleta e/o modulo php mod_rewrite non attivo).
Alla possibile comparsa dell&#8217;errore &#8220;NO INPUT FILE SPECIFIED&#8221;, bisognerebbe innanzitutto testare il  [...]]]></description>
			<content:encoded><![CDATA[<p>L&#8217;utilizzo delle impostazioni SEO/SEF in Joomla può generare qualche problema su alcuni hosting non configurati correttamente (versione di php obsoleta e/o modulo php mod_rewrite non attivo).</p>
<p>Alla possibile comparsa dell&#8217;errore &#8220;NO INPUT FILE SPECIFIED&#8221;, bisognerebbe innanzitutto testare il funzionamento del sito con tutte le opzioni SEO/SEF   disabilitate (nella sezione <em> Configurazione&gt;Sito  </em>impostare tutti i parametri su NO).</p>
<p>Se la navigazione del sito non presenta problemi con le opzioni SEO/SEF disabilitate, allora seguire i passi seguenti:</p>
<ol style="list-style-type: lower-roman;">
<li>Nella sezione <em>Configurazione&gt;Sito</em> abilitare le prime due voci;</li>
<li>Attraverso un client FTP o dal pannello di controllo dell&#8217; hoster, procurarsi il file htaccess.txt e modificarlo commentando la riga che riporta

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;"> Options +FollowSymLinks</pre></div></div>

<p>aggiungendo un simbolo di cancelletto (#) all&#8217;inizio della riga, in questo modo</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;"> # +FollowSymLinks</pre></div></div>

</li>
<li>Se il sito si trova in una sottocartella dello spazio web, sostituire la riga

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;"># RewriteBase /</pre></div></div>

<p>con</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">RewriteBase /nomecartella/</pre></div></div>

</li>
<li>Rinominare il file htaccess.txt in .htaccess e riposizionarlo nella root del sito web.</li>
<li>Se ancora dovessero presentarsi problemi, controllare la versione php utilizzata dall&#8217;hoster ed eventuali versioni del php.ini personalizzate. Anche se non più consigliata, la versione php 5.2.x non dovrebbe dare problemi con Joomla.</li>
</ol>
<p>PS. Il file .htaccess non può essere utilizzato su server Windows IIS oppure se il nostro hosting non supporta il mod_rewrite. In questi casi bisogna rinunciare alle impostazioni SEO/SEF impostando su NO tutte le voci presenti nella sezione <em>Configurazione&gt;Sito</em> del pannello di amministrazione di Joomla.</p>
<p>&nbsp;</p>
<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.sacaweb.com%2Fphp-mysql%2Ferrore-joomla-no-input-file-specified%2F&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:80px;" allowTransparency="true"></iframe>]]></content:encoded>
			<wfw:commentRss>http://www.sacaweb.com/php-mysql/errore-joomla-no-input-file-specified/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installare PEAR, PHPUnit, seleniumHQ in EasyPHP e Win7</title>
		<link>http://www.sacaweb.com/php-mysql/installare-pear-phpunit-seleniumhq-in-easyphp-e-win7/</link>
		<comments>http://www.sacaweb.com/php-mysql/installare-pear-phpunit-seleniumhq-in-easyphp-e-win7/#comments</comments>
		<pubDate>Mon, 19 Mar 2012 10:52:16 +0000</pubDate>
		<dc:creator>sacaweb</dc:creator>
				<category><![CDATA[Php/MySQL]]></category>
		<category><![CDATA[easyphp]]></category>
		<category><![CDATA[how install pear]]></category>
		<category><![CDATA[install pear]]></category>
		<category><![CDATA[PEAR]]></category>
		<category><![CDATA[phpunit]]></category>
		<category><![CDATA[selenium]]></category>
		<category><![CDATA[seleniumhq]]></category>

		<guid isPermaLink="false">http://www.sacaweb.com/?p=269</guid>
		<description><![CDATA[La  metodologia di sviluppo TDD (Test-driven development), come noto, aiuta a creare un ambiente in cui la suite di test cresce di pari passo con l&#8217;applicazione, questo perchè bisogna prima di tutto scrivere il codice di test e poi il codice da testare&#8230;
Strumenti utili a creare un ambiente di test  [...]]]></description>
			<content:encoded><![CDATA[<p>La  metodologia di sviluppo TDD (Test-driven development), come noto, aiuta a creare un ambiente in cui la suite di test cresce di pari passo con l&#8217;applicazione, questo perchè bisogna prima di tutto scrivere il codice di test e poi il codice da testare&#8230;</p>
<p>Strumenti utili a creare un ambiente di test nella programmazione php sono senza dubbio <strong>PHPUnit</strong> e <strong>seleniumHQ</strong>.<br />
PHPUnit presuppone la presenza del framework <strong>PEAR</strong>, perciò vediamo come installare il tutto.</p>
<p>Nelle versioni precedenti di EasyPhp era presente un file bat (<em>C:\Program Files (x86)\EasyPHP-5.3.6.0\php\go-pear.bat</em>) che permetteva di effettuare l&#8217;installazione di PEAR con facilità.</p>
<p>Nelle nuove versioni (EasyPHP 5.3.8 e 5.3.9) questo file non è incluso, perciò di seguito trovate i passi da effettuare per installare PEAR e PHPUnit con EasyPHP 5.3.9 e Win7.</p>
<p>Innanzitutto rinominare il file</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">      Programmi <span style="color: #009900;">&#40;</span>x86<span style="color: #009900;">&#41;</span>\EasyPHP<span style="color: #339933;">-</span>5<span style="color: #339933;">.</span>3<span style="color: #339933;">.</span>9\php\php539x120203095725\php<span style="color: #339933;">.</span>ini
      in 
      Programmi<span style="color: #009900;">&#40;</span>x86<span style="color: #009900;">&#41;</span>\EasyPHP<span style="color: #339933;">-</span>5<span style="color: #339933;">.</span>3<span style="color: #339933;">.</span>9\php\php539x120203095725\php<span style="color: #339933;">.</span>ini<span style="color: #339933;">.</span>old</pre></div></div>

<p>in quanto questo file procura un sacco di errori con le estensioni.</p>
<p>Creare un nuovo file <em>php.ini</em> vuoto nella stessa cartella (la mia è <em>Program Files (x86)\EasyPHP-5.3.9\php\php539x120203095725</em>).</p>
<p>L&#8217;unica riga che deve contenere il nuovo <em>php.ini</em> è la seguente:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">include_path <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;C:\DEV\PEAR<span style="color: #000099; font-weight: bold;">\\</span>pear&quot;</span><span style="color: #339933;">;</span>    <span style="color: #666666; font-style: italic;">//Nota il doppio slash tra PEAR\\pear</span></pre></div></div>

</p>
<div style='background-color:#eee;padding:5px;border:1px solid #ccc;'>
<p><strong>NOTA:</strong> In EasyPHP 5.3.9, per quanto riguarda la configurazione di Apache, viene utilizzato il <em>php.ini</em> contenuto nella cartella <em>C:\Program Files (x86)\EasyPHP-5.3.9\apache\php.ini</em> (come si può verificare anche con phpinfo()), mentre quando viene richiamato <em>php.exe</em> da linea di comando, i file da includere vengono ricavati dal <em>php.ini</em> contenuto in  <em>Programmi(x86)\EasyPHP-5.3.9\php\php539x120203095725\php.ini</em></p>
</div>
<p>Aggiungere 2 cartelle al Windows PATH. (Tasto destro su <em>Computer>proprietà>Impostazioni di sistema avanzate>Variabili d&#8217;ambiente>path</em>)</p>
<p>Mantenendo quelle già presenti, aggiungere alla fine le seguenti cartelle, separate da ;</p>
<ul>
<li>La cartella che contiene php.exe. (Sulla mia macchina è <em>C:\Program Files (x86)\EasyPHP-5.3.9\php\php539x120306151656;</em>)</li>
<li>La cartella dove si vuole che PEAR venga installato. (Io ho usato <em>C:\DEV\PEAR;</em>)</li>
</ul>
<p>Scaricare  <a href='http://pear.php.net/go-pear.phar' target='_blank'><em>http://pear.php.net/go-pear.phar</em></a></p>
<p>Shift + tasto destro  sulla cartella di download di <em>go-pear.phar</em> e poi > Apri finestra di comando qui</p>
<p>Nel prompt dei comandi : </p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">php go<span style="color: #339933;">-</span>pear<span style="color: #339933;">.</span>phar</pre></div></div>

<p>Premendo invio si installa il  system-wide PEAR (default)</p>
<p>Scegliere 1 per cambiare la cartella d&#8217;installazione. Io ho scelto <em>C:\DEV\PEAR</em>. </p>
<p>Lasciare le altre opzioni invariate.  Premere 2 volte invio quando richiesto.</p>
<p>Se durante l&#8217;installazione un warning vi avverte che l&#8217;<em>include_path</em> nell&#8217;attuale <em>php.ini</em> non contiene il percorso giusto, scegliere Y per effettuare la modifica automaticamente.</p>
<p>Verrà creato un file <em>.reg</em> nella cartella indicata, doppio click per eseguirlo. (<em>C:\DEV\PEAR\PEAR_ENV.reg</em>)</p>
<p>PEAR è installato. Digitando</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">pear help</pre></div></div>

<p>nel prompt dei comandi dovrebbe apparire una lista di tutti i comandi disponibili.</p>
<p>Per installare PHPUnit digitare nel prompt:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">    pear channel<span style="color: #339933;">-</span>discover pear<span style="color: #339933;">.</span>phpunit<span style="color: #339933;">.</span>de            <span style="color: #666666; font-style: italic;"># aggiunge il canale
</span>    pear channel<span style="color: #339933;">-</span>discover pear<span style="color: #339933;">.</span>symfony<span style="color: #339933;">-</span>project<span style="color: #339933;">.</span>com   <span style="color: #666666; font-style: italic;"># aggiunge il canale
</span>    pear channel<span style="color: #339933;">-</span>discover components<span style="color: #339933;">.</span>ez<span style="color: #339933;">.</span>no           <span style="color: #666666; font-style: italic;"># aggiunge il canale
</span>    pear clear<span style="color: #339933;">-</span>cache                                 <span style="color: #666666; font-style: italic;">#cancella la cache dei web services
</span>    pear upgrade <span style="color: #339933;">--</span>force PEAR                        <span style="color: #666666; font-style: italic;"># aggiorna all'ultima versione
</span>    pear install <span style="color: #339933;">--</span>alldeps phpunit<span style="color: #339933;">/</span>PHPUnit           <span style="color: #666666; font-style: italic;"># installa phpunit</span></pre></td></tr></table></div>

<p>Se l&#8217;installazione di PHPUnit è andata a buon fine, digitando al prompt dei comandi</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">phpunit</pre></div></div>

<p>     dovrebbe comparire l&#8217;help di phpunit, con la lista di tutti le opzioni disponibili.
    </p>
<p>Per installare Selenium Server <a href='http://selenium.googlecode.com/files/selenium-server-standalone-2.20.0.jar' target='_blank'>scaricare il file jar</a> in una cartella facilmente raggiungibile (io l&#8217;ho salvato in C:\DEV).</p>
<p>Per eseguire il server bisogna che sia installato il JRE (Java Runtime Environment) e che la cartella <em>bin </em>(nel mio pc è C:\Programmi\Java\jre6\bin) sia nel path. Poi portarsi nella cartella dove si è salvato il file jar del server e digitare nel prompt</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">java <span style="color: #339933;">-</span>jar selenium<span style="color: #339933;">-</span>server<span style="color: #339933;">-</span>standalone<span style="color: #339933;">-</span>2<span style="color: #339933;">.</span>20<span style="color: #339933;">.</span>0<span style="color: #339933;">.</span>jar</pre></div></div>

<p>Per integrare il server selenium direttamente in PHPUnit, bisogna innanzitutto aggiungere al php.ini la seguente riga:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">extension<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;C:\PROGRA~1\EASYPH~1.9\php\php539x120203095725\ext\php_curl.dll&quot;</span></pre></div></div>

<p>Oppure</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">extension_dir <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;C:\PROGRA~2\EASYPH~1.9<span style="color: #000099; font-weight: bold;">\\</span>php\php539x120203095725\ext<span style="color: #000099; font-weight: bold;">\&quot;</span>
extension=php_bz2.dll
extension=php_curl.dll
extension=php_gd2.dll
extension=php_mbstring.dll
extension=php_mysql.dll
extension=php_mysqli.dll
extension=php_pdo_mysql.dll
extension=php_pdo_sqlite.dll
extension=php_sqlite3.dll</span></pre></td></tr></table></div>

<p>Poi digitare nel prompt</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">pear install phpunit<span style="color: #339933;">/</span>PHPUnit_Selenium</pre></div></div>

<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.sacaweb.com%2Fphp-mysql%2Finstallare-pear-phpunit-seleniumhq-in-easyphp-e-win7%2F&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:80px;" allowTransparency="true"></iframe>]]></content:encoded>
			<wfw:commentRss>http://www.sacaweb.com/php-mysql/installare-pear-phpunit-seleniumhq-in-easyphp-e-win7/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>&#8220;Attenzione! &#8211; Operazione di spostamento file fallita&#8221; in Joomla 1.5</title>
		<link>http://www.sacaweb.com/php-mysql/attenzione-operazione-di-spostamento-file-fallita-in-joomla-1-5/</link>
		<comments>http://www.sacaweb.com/php-mysql/attenzione-operazione-di-spostamento-file-fallita-in-joomla-1-5/#comments</comments>
		<pubDate>Wed, 08 Feb 2012 15:43:47 +0000</pubDate>
		<dc:creator>sacaweb</dc:creator>
				<category><![CDATA[Php/MySQL]]></category>
		<category><![CDATA[installazione moduli]]></category>
		<category><![CDATA[joomla]]></category>
		<category><![CDATA[permessi files]]></category>

		<guid isPermaLink="false">http://www.sacaweb.com/?p=249</guid>
		<description><![CDATA[Se dovesse malauguratamente comparire il messaggio in oggetto, magari mentre si prova ad installare un componente, un modulo oppure un template, provate ad effettuare i seguenti passi:
	 &#8211; Nell&#8217;area di amministrazione di Joomla 1.5, cliccare su AiutoInfo sistema;
         &#8211; Nella voce permessi  [...]]]></description>
			<content:encoded><![CDATA[<p>Se dovesse malauguratamente comparire il messaggio in oggetto, magari mentre si prova ad installare un componente, un modulo oppure un template, provate ad effettuare i seguenti passi:<br />
	 &#8211; Nell&#8217;area di amministrazione di Joomla 1.5, cliccare su Aiuto>Info sistema;<br />
         &#8211; Nella voce permessi cartelle, controllare che tutti i file siano scrivibili, in caso contrario, modificare i permessi con un editor ftp.<br />
Attenzione che i percorsi delle cartelle tmp e logs devono essere specificati e possibilmente con path assoluto.</p>
<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.sacaweb.com%2Fphp-mysql%2Fattenzione-operazione-di-spostamento-file-fallita-in-joomla-1-5%2F&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:80px;" allowTransparency="true"></iframe>]]></content:encoded>
			<wfw:commentRss>http://www.sacaweb.com/php-mysql/attenzione-operazione-di-spostamento-file-fallita-in-joomla-1-5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Lettere maiuscole accentate in php utf8</title>
		<link>http://www.sacaweb.com/php-mysql/lettere-maiuscole-accentate-in-php-utf8/</link>
		<comments>http://www.sacaweb.com/php-mysql/lettere-maiuscole-accentate-in-php-utf8/#comments</comments>
		<pubDate>Wed, 10 Aug 2011 12:16:10 +0000</pubDate>
		<dc:creator>sacaweb</dc:creator>
				<category><![CDATA[Php/MySQL]]></category>
		<category><![CDATA[lettere maiuscole]]></category>
		<category><![CDATA[maiuscolo]]></category>
		<category><![CDATA[strtoupper]]></category>
		<category><![CDATA[uppercase utf8]]></category>

		<guid isPermaLink="false">http://www.sacaweb.com/?p=236</guid>
		<description><![CDATA[Può capitare di voler trasformare in php una frase in maiuscolo e che questa contenga dei caratteri accentati.
Premessa : i caratteri DEVONO essere codificati in utf8.
Ho visto in giro per il web una miriade di funzioni che sostituiscono tutti i possibili caratteri accentati, sia con l&#8217;uso delle  [...]]]></description>
			<content:encoded><![CDATA[<p>Può capitare di voler trasformare in php una frase in maiuscolo e che questa contenga dei caratteri accentati.<br />
Premessa : i caratteri DEVONO essere codificati in utf8.<br />
Ho visto in giro per il web una miriade di funzioni che sostituiscono tutti i possibili caratteri accentati, sia con l&#8217;uso delle regexp sia con str_replace&#8230;non serve nulla di tutto ciò.<br />
Ci viene in aiuto una funzione php :</p>
<p><em>string mb_strtoupper ( string $str [, string $encoding] )</em></p>
<p>ritorna una stringa con tutti i caratteri convertiti in maiuscolo e codificati in $encoding .</p>
<p>ad esempio:</p>
<p>$str = &#8220;àèìòù&#8221;;<br />
echo mb_strtoupper($str ,&#8221;UTF-8&#8243;);  // ÀÈÌÒÙ</p>
<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.sacaweb.com%2Fphp-mysql%2Flettere-maiuscole-accentate-in-php-utf8%2F&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:80px;" allowTransparency="true"></iframe>]]></content:encoded>
			<wfw:commentRss>http://www.sacaweb.com/php-mysql/lettere-maiuscole-accentate-in-php-utf8/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Anti spam: nascondere indirizzo email</title>
		<link>http://www.sacaweb.com/strumenti-utili/anti-spam-nascondere-indirizzo-email/</link>
		<comments>http://www.sacaweb.com/strumenti-utili/anti-spam-nascondere-indirizzo-email/#comments</comments>
		<pubDate>Fri, 15 Jul 2011 13:41:49 +0000</pubDate>
		<dc:creator>sacaweb</dc:creator>
				<category><![CDATA[Strumenti utili]]></category>
		<category><![CDATA[antispam]]></category>
		<category><![CDATA[email obfuscator]]></category>
		<category><![CDATA[nascondere email]]></category>
		<category><![CDATA[obfuscator]]></category>

		<guid isPermaLink="false">http://www.sacaweb.com/?p=180</guid>
		<description><![CDATA[Email obfuscator

Email da nascondere:

Nome opzionale da visualizzare nel link:

Link nascosto:

Anteprima nel browser: 


]]></description>
			<content:encoded><![CDATA[<h3>Email obfuscator</h3>
<form name="obf_email_frm" id="obf_email_frm" method="post" action="">
Email da nascondere:</p>
<input type="email" name="e" id="e" value="" placeholder="info@miosito.it" size="50" required />
<p>Nome opzionale da visualizzare nel link:</p>
<input type="text" name="n" id="n" value="" size="50" />
<p>Link nascosto:<br />
<textarea id="link_obf" name="link_obf" style="width: 370px; height: 150px;border:1px solid #ccc;" title='Copia e incolla questo testo nel codice html della tua pagina web'></textarea><br />
Anteprima nel browser: <a href=''></a></p>
<input type="submit" id="invia" name="invia" value="Invia" />
</p></form>
<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.sacaweb.com%2Fstrumenti-utili%2Fanti-spam-nascondere-indirizzo-email%2F&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:80px;" allowTransparency="true"></iframe>]]></content:encoded>
			<wfw:commentRss>http://www.sacaweb.com/strumenti-utili/anti-spam-nascondere-indirizzo-email/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Popolare una select con javascript, jQuery, Ajax, php</title>
		<link>http://www.sacaweb.com/javascript-jquery-ajax/popolare-una-select-con-javascript-jquery-ajax-php/</link>
		<comments>http://www.sacaweb.com/javascript-jquery-ajax/popolare-una-select-con-javascript-jquery-ajax-php/#comments</comments>
		<pubDate>Wed, 20 Apr 2011 23:43:51 +0000</pubDate>
		<dc:creator>sacaweb</dc:creator>
				<category><![CDATA[Javascript/JQuery/Ajax]]></category>
		<category><![CDATA[Php/MySQL]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[popolare select]]></category>
		<category><![CDATA[popolare select dinamicamente]]></category>

		<guid isPermaLink="false">http://www.sacaweb.com/?p=168</guid>
		<description><![CDATA[Al giorno d&#8217;oggi il web è pieno zeppo di pagine che, grazie a richieste asincrone (ajax), aggiornano porzioni di esse senza effettuare un caricamento di tutta la pagina.
Un &#34;problema&#34; ricorrente è popolare una select in base alla scelta effettuata in un&#8217;altra select. Un esempio è quello delle  [...]]]></description>
			<content:encoded><![CDATA[<p>Al giorno d&#8217;oggi il web è pieno zeppo di pagine che, grazie a richieste asincrone (ajax), aggiornano porzioni di esse senza effettuare un caricamento di tutta la pagina.</p>
<p>Un &quot;problema&quot; ricorrente è popolare una select in base alla scelta effettuata in un&#8217;altra select. Un esempio è quello delle regioni e città: si seleziona una regione dalla prima select e tramite ajax si popola la seconda select con le sole città della regione scelta. Ma ci sono migliaia di esempi e casi d&#8217;uso.</p>
<p><a href="http://www.sacaweb.com/blog/blogspot4/" target="_blank">Guarda Demo</a></p>
<p>Vediamo come sia semplice realizzare tutto con l&#8217;aiuto di jQuery.</p>
<p>Come esempio base ci basta un file html che contiene le select ed un file php al quale viene inoltrata la richiesta asincrona e che ci restituisce i dati in base ai parametri passati.</p>
<p>Nella sezione head del file html:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span> src<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;http://code.jquery.com/jquery-1.5.2.min.js&quot;</span><span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span> charset<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;utf-8&quot;</span><span style="color: #339933;">&gt;</span>
    $<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	   $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;select#primaselect&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">change</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		 $.<span style="color: #660066;">getJSON</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;select.php&quot;</span><span style="color: #339933;">,</span><span style="color: #009900;">&#123;</span>id<span style="color: #339933;">:</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>dati<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #003366; font-weight: bold;">var</span> options <span style="color: #339933;">=</span> <span style="color: #3366CC;">''</span><span style="color: #339933;">;</span>
			<span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> dati.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				options <span style="color: #339933;">+=</span> <span style="color: #3366CC;">'&lt;option value=&quot;'</span> <span style="color: #339933;">+</span> dati<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">valore</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&quot;&gt;'</span> <span style="color: #339933;">+</span> dati<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">etichetta</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;/option&gt;'</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#secondaselect&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span>options<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#secondaselect option:first'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'selected'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'selected'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>Nel body del file html:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">b</span>&gt;</span>Scegli il tuo smartphone preferito:<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">b</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">select</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;primaselect&quot;</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&quot;</span>&gt;</span>Scegli<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;1&quot;</span>&gt;</span>HTC<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;2&quot;</span>&gt;</span>SAMSUNG<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;3&quot;</span>&gt;</span>MOTOROLA<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">select</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">select</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;secondaselect&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">select</span>&gt;</span></pre></td></tr></table></div>

<p>Contenuto del file php:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
  <span style="color: #000088;">$dati</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000088;">$id</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'id'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
     <span style="color: #990000;">array_push</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dati</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;valore&quot;</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">&quot;cod_001&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;etichetta&quot;</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">&quot;Desire HD&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #990000;">array_push</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dati</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;valore&quot;</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">&quot;cod_002&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;etichetta&quot;</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">&quot;Flyer&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #990000;">array_push</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dati</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;valore&quot;</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">&quot;cod_003&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;etichetta&quot;</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">&quot;Chacha&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #990000;">array_push</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dati</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;valore&quot;</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">&quot;cod_004&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;etichetta&quot;</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">&quot;HD2&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
     <span style="color: #990000;">array_push</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dati</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;valore&quot;</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">&quot;cod_005&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;etichetta&quot;</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">&quot;Galaxi S&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #990000;">array_push</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dati</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;valore&quot;</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">&quot;cod_006&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;etichetta&quot;</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">&quot;Wave II&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #990000;">array_push</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dati</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;valore&quot;</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">&quot;cod_007&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;etichetta&quot;</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">&quot;Omnia 7&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #990000;">array_push</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dati</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;valore&quot;</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">&quot;cod_008&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;etichetta&quot;</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">&quot;Omnia HD&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
     <span style="color: #990000;">array_push</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dati</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;valore&quot;</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">&quot;cod_009&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;etichetta&quot;</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">&quot;Atrix 4G&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #990000;">array_push</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dati</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;valore&quot;</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">&quot;cod_010&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;etichetta&quot;</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">&quot;Droid Bionic&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #990000;">array_push</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dati</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;valore&quot;</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">&quot;cod_011&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;etichetta&quot;</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">&quot;Cliq 2&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #990000;">array_push</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dati</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;valore&quot;</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">&quot;cod_012&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;etichetta&quot;</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">&quot;Bravo&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #009900;">&#125;</span>
&nbsp;
   <span style="color: #b1b100;">echo</span> <span style="color: #990000;">json_encode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dati</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>In questo caso il file php recupera i dati da alcuni array costruiti ad hoc per l&#8217;esempio, ma nulla vieta (anzi si spera) che i dati siano recuperati da un db.</p>
<p>Per qualsiasi chiarimento, a disposizione.</p>
<p><a href="http://www.sacaweb.com/blog/blogspot4/" target="_blank">Guarda demo</a></p>
<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.sacaweb.com%2Fjavascript-jquery-ajax%2Fpopolare-una-select-con-javascript-jquery-ajax-php%2F&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:80px;" allowTransparency="true"></iframe>]]></content:encoded>
			<wfw:commentRss>http://www.sacaweb.com/javascript-jquery-ajax/popolare-una-select-con-javascript-jquery-ajax-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Riscrivere url dinamicamente con jQuery</title>
		<link>http://www.sacaweb.com/javascript-jquery-ajax/riscrivere-url-dinamicamente-con-jquery/</link>
		<comments>http://www.sacaweb.com/javascript-jquery-ajax/riscrivere-url-dinamicamente-con-jquery/#comments</comments>
		<pubDate>Mon, 04 Apr 2011 22:32:51 +0000</pubDate>
		<dc:creator>sacaweb</dc:creator>
				<category><![CDATA[Javascript/JQuery/Ajax]]></category>
		<category><![CDATA[Php/MySQL]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[jquery history]]></category>
		<category><![CDATA[riscrivere url dinamicamente]]></category>
		<category><![CDATA[window.location.hash]]></category>

		<guid isPermaLink="false">http://www.sacaweb.com/?p=153</guid>
		<description><![CDATA[Com&#8217;è noto, Ajax permette di effettuare richieste asincrone ad un web server via Javascript, senza ricaricare la pagina e senza cambiare url nella barra degli indirizzi.
Le richieste asincrone effettuate con Ajax hanno spesso lo scopo di modificare parti della pagina html. Effettuando varie  [...]]]></description>
			<content:encoded><![CDATA[<p>Com&#8217;è noto, Ajax permette di effettuare richieste asincrone ad un web server via Javascript, senza ricaricare la pagina e senza cambiare url nella barra degli indirizzi.</p>
<p>Le richieste asincrone effettuate con Ajax hanno spesso lo scopo di modificare parti della pagina html. Effettuando varie richieste consecutive, ci si può trovare innanzi ad una pagina completamente diversa da quella iniziale, ma con uno stesso url nella barra degli indirizzi!</p>
<p>Esempio: Il sito <em>www.sitodiannunci.it</em>, alla pagina <em>annunci.php</em> permette di navigare tra gli annunci di una categoria mediante due pulsanti <em>avanti </em>e <em>indietro</em>. Il contenuto della pagina <em>annunci.php</em> cambia, mostrando i dati relativi al nuovo annuncio caricati via Ajax.</p>
<p>Dopo varie pressioni dei pulsanti <em>avanti </em>e <em>indietro</em>, l&#8217;utente decide di salvare la pagina tra i preferiti perchè interessato all&#8217;annuncio. Cosa succede? Viene salvata la stringa <em>www.sitodiannunci.it/annunci.php</em>, ma da questa non si riesce a&nbsp; risalire all&#8217;annuncio di interesse. E&#8217; chiaro che servirebbe una variabile da aggiungere alla <em>query string</em> che identifichi univocamente un annuncio, tipo <em>www.sitodiannunci.it/annunci.php?id=123</em>.</p>
<p>Se si modifica l&#8217;url della pagina ad ogni annuncio con un linguaggio lato server tipo php, si ottiene il ricaricamento della pagina che non è un effetto voluto (altrimenti perchè stiamo usando Ajax?). Stesso risultato se modifichiamo la proprietà <em>window.location.href</em>&nbsp; via javascript.&nbsp; Allora come risolvere???</p>
<p>Ci viene in aiuto una proprietà poco conosciuta&nbsp; dell&#8217;oggetto <em>location </em>javascript: <em>window.location<strong>.hash</strong>.</em></p>
<p>La stringa contenuta in <em>window.location.hash</em> sarà aggiunta in coda all&#8217;url della pagina, preceduta dal simbolo cancelletto <strong>#</strong> , senza ricaricare la pagina, ad esempio&nbsp; <em>www.sitoannunci.it/annunci.php<strong>#123 </strong></em></p>
<p>Salvando nei preferiti&nbsp; <em>www.sitoannunci.it/annunci.php<strong>#123 </strong></em><span style="font-style: italic;">&nbsp; la proprietà</span> <em>window.location.hash </em>conterrà la stringa 123 che può servire a risalire all&#8217;annuncio di interesse.</p>
<p>Abbiamo visto come risalire al contenuto di un annuncio&nbsp; impostando e poi leggendo la proprietà javascript <em>window.location.hash</em> .</p>
<p>E non è tutto. Si poteva mai parlare di javascript senza nominare jQuery??? Certo che no. Esiste infatti un plugin,<strong><em> jquery.history</em></strong>, che rende tutto semplicissimo.</p>
<p>jQuery history plugin aiuta a supportare i pulsanti avanti/indietro ed il bookmarks nelle applicazioni javascript. Permette di salvare lo stato nell&#8217;url hash e di ripristinarlo.</p>
<p><a href="http://www.sacaweb.com/blog/blogpost3/index.html" target="_blank">live demo</a>&nbsp;&nbsp;&nbsp; ( consultare il codice sorgente )</p>
<p>Ci sono 2 metodi per interagire con l&#8217;oggetto jQuery.history:</p>
<h3>jQuery.history.init(callback [, options])</h3>
<p>Inizializza il plugin e va richiamato una volta quando la pagina è completamente caricata.</p>
<p>&nbsp;</p>
<h3>jQuery.history.load(hash)</h3>
<p>Carica una stringa in <code>location.hash</code>,crea una nuova entry nella storia della navigazione e invoca la funzione di callback se necessario.&nbsp; A meno che&nbsp; l&#8217;hash passato come parametro sia diverso da quello corrente, la funzione di callback non è invocata.</p>
<p>
	<a href="http://tkyk.github.com/jquery-history-plugin/#documentation" target="_blank">Documentazione completa (in inglese)</a></p>
<p>&nbsp;</p>
<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.sacaweb.com%2Fjavascript-jquery-ajax%2Friscrivere-url-dinamicamente-con-jquery%2F&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:80px;" allowTransparency="true"></iframe>]]></content:encoded>
			<wfw:commentRss>http://www.sacaweb.com/javascript-jquery-ajax/riscrivere-url-dinamicamente-con-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery Vertical Scroller Plus Plugin</title>
		<link>http://www.sacaweb.com/javascript-jquery-ajax/jquery-vertical-scroller-plus-plugin/</link>
		<comments>http://www.sacaweb.com/javascript-jquery-ajax/jquery-vertical-scroller-plus-plugin/#comments</comments>
		<pubDate>Wed, 23 Feb 2011 23:21:49 +0000</pubDate>
		<dc:creator>sacaweb</dc:creator>
				<category><![CDATA[Javascript/JQuery/Ajax]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[scroller]]></category>
		<category><![CDATA[scrolling]]></category>
		<category><![CDATA[vertical scroller]]></category>

		<guid isPermaLink="false">http://www.sacaweb.com/?p=142</guid>
		<description><![CDATA[Ho scritto questo plugin jQuery che trasforma un div contenitore(wrapper) che contiene un div figlio(scroller) in un riquadro con contenuto scorrevole verticalmente usando due pulsanti su e giù.
Guarda la demo live
Testato e funzionante anche su dispositivi mobili touch screen iphone e Android !
Il  [...]]]></description>
			<content:encoded><![CDATA[<p>Ho scritto questo plugin jQuery che trasforma un div contenitore(wrapper) che contiene un div figlio(scroller) in un riquadro con contenuto scorrevole verticalmente usando due pulsanti su e giù.</p>
<p><a href="http://www.sacaweb.com/blog/blogpost2/vertical_scroller_plus.html" target="_blank">Guarda la demo live</a></p>
<p>Testato e funzionante anche su dispositivi mobili touch screen iphone e Android !</p>
<p>Il contenuto del div scroller può essere qualsiasi elemento html (anche solo una tabella, a differenza di altri plugin! <img src='http://www.sacaweb.com/blog/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' />  )</p>
<p>Il plugin calcola automaticamente l&#8217;altezza del div scroller.</p>
<p>Si possono utilizzare più istanze di scroller nella stessa pagina <strong>cambiando semplicemente gli id del div wrapper, del div scroller e dei pulsanti.</strong></p>
<p>Si può impostare di quanti pixel deve scorrere il contenuto e la velocità di scorrimento.</p>
<p>Facilissimo da usare:</p>
<ul>
<li>basta creare due div, uno dentro l&#8217;altro;</li>
<li>il div esterno sarà il contenitore;</li>
<li>il div interno sarà lo scroller;</li>
<li>due pulsanti per scorrere su e giù;</li>
<li>tutti gli elementi inseriti all&#8217;interno del div scroller scorreranno alla pressione dei pulsanti.</li>
</ul>
<p>&nbsp;</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;wrapper&quot;</span> <span style="color: #000066;">style</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;width:350px;height:120px;&quot;</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;scroller&quot;</span>&gt;</span>. . . <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;su_btn&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;button&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;su&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span> 
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;giu_btn&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;button&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;giù&quot;</span> <span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span></pre></td></tr></table></div>

<p>Includere i files jQuery e applicare il plugin al div contenitore:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://code.jquery.com/jquery-1.5.min.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;jquery.verticalscrollplus-1.0.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">language</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;JavaScript&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;</span>
  $(document).ready(function(){
      $(&quot;#wrapper&quot;).verticalScrollPlus({step:100});
      $(&quot;#wrapper2&quot;).verticalScrollPlus({speed: 1500, step: 50, upID: &quot;#su_btn2&quot;, downID: &quot;#giu_btn2&quot;, scrollerID:&quot;#scroller2&quot; });
  });
  <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span></pre></td></tr></table></div>

<div style='color:white;text-shadow: 1px 1px 1px #000;font:bold 14px Arial;background-color:#b4e11e;padding:5px;border:1px solid red;border-radius: 10px; -moz-border-radius: 10px; -webkit-border-radius: 10px; '>
<p>Se reputi che il jQuery Vertical Scroller Plus Plugin ti sia stato utile, pensa ad una libera donazione come incentivo allo sviluppo futuro. Ti ringrazio anticipatamente.</p>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="NA3XVUZN2YUUY">
<input type="image" src="https://www.paypalobjects.com/it_IT/IT/i/btn/btn_donateCC_LG.gif" border="0" name="submit" alt="PayPal - Il sistema di pagamento online più facile e sicuro!">
<img alt="" border="0" src="https://www.paypalobjects.com/it_IT/i/scr/pixel.gif" width="1" height="1"><br />
</form>
</div>
<p>Il plugin può essere scaricato da:</p>
<p style='text-decoration: line-through; '>http://plugins.jquery.com/content/verticalscrollerplus-10</p>
<p><a href='http://www.sacaweb.com/blog/blogpost2/jquery.verticalscrollplus-1.0.js' target='_blank'>jquery.verticalscrollplus-1.0.js</a></p>
<p>Plugin options:</p>
<ul>
<li><em><strong>speed</strong> : quanto è veloce l&#8217;animazione di scorrimento verticale;(default = 500)</em></li>
<li><em><strong>step</strong>: di quanti pixel scorre il contenuto ad ogni pressione di tasto su oppure giù;(default = 60)</em></li>
<li><em><strong>upID</strong>: id dell&#8217;elemento che fa partire l&#8217;animazione verso su;(default = #su_btn)</em></li>
<li><em><strong>downID</strong>: id dell&#8217;elemento che fa partire l&#8217;animazione verso giù;(default = #giu_btn)</em></li>
<li><em><strong>scrollerID</strong>: id dell&#8217;elemento il cui contenuto scorrerà verticalmente;(default = #scroller)</em></li>
</ul>
<p></p>
<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.sacaweb.com%2Fjavascript-jquery-ajax%2Fjquery-vertical-scroller-plus-plugin%2F&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:80px;" allowTransparency="true"></iframe>]]></content:encoded>
			<wfw:commentRss>http://www.sacaweb.com/javascript-jquery-ajax/jquery-vertical-scroller-plus-plugin/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Etichetta di caricamento Ajax tipo Google</title>
		<link>http://www.sacaweb.com/javascript-jquery-ajax/etichetta-di-caricamento-ajax-tipo-google/</link>
		<comments>http://www.sacaweb.com/javascript-jquery-ajax/etichetta-di-caricamento-ajax-tipo-google/#comments</comments>
		<pubDate>Thu, 20 Jan 2011 21:07:55 +0000</pubDate>
		<dc:creator>sacaweb</dc:creator>
				<category><![CDATA[Javascript/JQuery/Ajax]]></category>
		<category><![CDATA[Ajax Loading Google Like]]></category>

		<guid isPermaLink="false">http://www.sacaweb.com/?p=91</guid>
		<description><![CDATA[Oggi vediamo un modo per realizzare un avviso di loading Ajax tipo Google.
Mi riferisco alla&#160; etichetta di loading che compare in alto nella pagina&#160; ogni qualvolta eseguiamo un&#8217;azione tipo eliminare un messaggio (che evidentemente effettua richieste Ajax) all&#8217;interno ad esempio di GMail.
Con  [...]]]></description>
			<content:encoded><![CDATA[<p>Oggi vediamo un modo per realizzare un avviso di loading Ajax tipo Google.</p>
<p>Mi riferisco alla&nbsp; etichetta di loading che compare in alto nella pagina&nbsp; ogni qualvolta eseguiamo un&#8217;azione tipo eliminare un messaggio (che evidentemente effettua richieste Ajax) all&#8217;interno ad esempio di GMail.</p>
<p>Con l&#8217;aiuto di JQuery diventa tutto semplicissimo. <a href="blog/blogpost1/loading_google_like.html" target="_blank">Vedi la demo live.</a></p>
<p>Di seguito la parte più importante del codice javascript:<br />
	&nbsp;</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
         <span style="color: #009966; font-style: italic;">/* quando si preme il pulsante si carica il contenuto da un file di testo  */</span>
         $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#loadingbtn'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
             $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#contenuto'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">load</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'file.txt'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
         <span style="color: #006600; font-style: italic;">/* quando parte la richiesta Ajax mostra il div di loading, quando la richiesta
            viene completata nasconde il div  */</span>
         $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#loading'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ajaxSend</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
           $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">fadeIn</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'slow'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ajaxComplete</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
           $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">fadeOut</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'slow'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
 <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>&nbsp;</p>
<p>Di seguito il codice html della pagina:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>Clicca sul pulsante per caricare via Ajax del contenuto nel div sotto<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;button&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;loadingbtn&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;loadingbtn&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Carica contenuto&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">br</span> <span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">br</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;contenuto&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;contenuto&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;loading&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;loading&quot;</span>&gt;</span>Loading...<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></td></tr></table></div>

<p>Importante la regola css che imposta lo stato iniziale dell&#8217;avviso di loading su invisibile, in quanto è su questa che va ad agire javascript al verificarsi degli eventi ajaxSend e ajaxComplete.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#loading</span><span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">fixed</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">green</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #993333;">white</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">80px</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.sacaweb.com%2Fjavascript-jquery-ajax%2Fetichetta-di-caricamento-ajax-tipo-google%2F&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:80px;" allowTransparency="true"></iframe>]]></content:encoded>
			<wfw:commentRss>http://www.sacaweb.com/javascript-jquery-ajax/etichetta-di-caricamento-ajax-tipo-google/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Selezionare radiobox da jQuery</title>
		<link>http://www.sacaweb.com/javascript-jquery-ajax/selezionare-radiobox-da-jquery/</link>
		<comments>http://www.sacaweb.com/javascript-jquery-ajax/selezionare-radiobox-da-jquery/#comments</comments>
		<pubDate>Wed, 29 Dec 2010 00:18:28 +0000</pubDate>
		<dc:creator>sacaweb</dc:creator>
				<category><![CDATA[Javascript/JQuery/Ajax]]></category>

		<guid isPermaLink="false">http://www.sacaweb.com/?p=66</guid>
		<description><![CDATA[Quando selezioniamo un componente radiobox col mouse succedono almeno due cose:

Il pallino del radiobox viene annerito ad indicare che &#232; selezionato;
Viene lanciato un evento javascript di tipo onchange, che volendo pu&#242; essere intercettato.

Supponiamo di avere un gruppo di radiobox che  [...]]]></description>
			<content:encoded><![CDATA[<p>Quando selezioniamo un componente radiobox col mouse succedono almeno due cose:</p>
<ol>
<li>Il pallino del radiobox viene annerito ad indicare che &egrave; selezionato;</li>
<li>Viene lanciato un evento javascript di tipo onchange, che volendo pu&ograve; essere intercettato.</li>
</ol>
<p>Supponiamo di avere un gruppo di radiobox che rappresentano colori:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>input <span style="color: #000066;">name</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;colori&quot;</span> type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;radio&quot;</span> value<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;red&quot;</span> <span style="color: #339933;">/&gt;</span> Rosso 
<span style="color: #339933;">&lt;</span>input <span style="color: #000066;">name</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;colori&quot;</span> type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;radio&quot;</span> value<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;green&quot;</span> <span style="color: #339933;">/&gt;</span> Verde 
<span style="color: #339933;">&lt;</span>input <span style="color: #000066;">name</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;colori&quot;</span> type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;radio&quot;</span> value<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;blue&quot;</span> <span style="color: #339933;">/&gt;</span> Blu
&nbsp;
<span style="color: #339933;">&lt;</span>span id<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;risposta&quot;</span><span style="color: #339933;">&gt;&lt;/</span>span<span style="color: #339933;">&gt;</span></pre></div></div>

<p>Grazie alla potenza di jQuery &egrave; semplice intercettare l&#39;evento onchange quando si seleziona un radiobox:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;input[name=colori]:radio&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">change</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#risposta&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">value</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#risposta&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;color&quot;</span><span style="color: #339933;">,</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">value</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Quando si seleziona un radiobox, il corrispondente colore viene scritto in un elemento span con id=&quot;risposta&quot;. Da notare anche come sia semplice modificare lo stile di un elemento.</p>
<p>Ma come si potrebbe simulare il click del mouse da jQuery?</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> colore <span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;red&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>colore <span style="color: #339933;">!=</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
   $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;input[value=&quot;</span><span style="color: #339933;">+</span>colore<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;]:radio&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'checked'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Attraverso il metodo attr(), risulta semplice modificare l&#39;attributo checked del radiobox.</p>
<p>Sembrerebbe bastare, ma la modifica dell&#39;attributo checked attraverso il metodo attr() ottiene come risultato la sola selezione del radiobox, senza lanciare alcun evento onchange.</p>
<p>Dando il valore &#8220;red&#8221; alla variabile colore, si ottiene la selezione del radiobox corrispondente, ma non viene scritto nulla nell&#39;elemento con id=&#8221;risposta&#8221;. Questo perch&egrave; attraverso la sola modifica dell&#39;attributo col metodo attr() non viene lanciato l&#39;evento onchange.</p>
<p>Si pu&ograve; per&ograve; lanciare l&#39;evento onchange manualmente attraverso il codice</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">&nbsp;
 $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;input[value=&quot;</span><span style="color: #339933;">+</span>colore<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;]:radio&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">change</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Il codice finale &egrave;</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">&lt;input name=&quot;colori&quot; type=&quot;radio&quot; value=&quot;red&quot; /&gt;Rosso
&lt;input name=&quot;colori&quot; type=&quot;radio&quot; value=&quot;green&quot; /&gt;Verde
&lt;input name=&quot;colori&quot; type=&quot;radio&quot; value=&quot;blue&quot; /&gt;Blu
&nbsp;
&lt;span id=&quot;risposta&quot;&gt;&lt;/span&gt;
&nbsp;
<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #003366; font-weight: bold;">var</span> colore <span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;red&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>colore <span style="color: #339933;">!=</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;input[value=&quot;</span><span style="color: #339933;">+</span>colore<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;]:radio&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'checked'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;input[name=colori]:radio&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">change</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
         $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#risposta&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">value</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#risposta&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;color&quot;</span><span style="color: #339933;">,</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">value</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;input[value=&quot;</span><span style="color: #339933;">+</span>colore<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;]:radio&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">change</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p><a class="fancybox-iframe" href="http://www.sacaweb.com/blog/prova_radiobox.html">Guarda il risultato</a></p>
<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.sacaweb.com%2Fjavascript-jquery-ajax%2Fselezionare-radiobox-da-jquery%2F&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:80px;" allowTransparency="true"></iframe>]]></content:encoded>
			<wfw:commentRss>http://www.sacaweb.com/javascript-jquery-ajax/selezionare-radiobox-da-jquery/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

