Forums

Passing values ​​from a dropdown which is working with ajax

AntonioGraca 02 Oct, 2013
Hello, Bob

I have two dropdown wherein the second (ajax by event) work dependence on the first.
When the form loads the second box has nothing and when I select an option in the first dropdown loads a listing on 2nd under certain conditions. So far so good, works very well.
However, I want use the values ​​of these two dropdowns to pass these values ​​to another form. The value of the first (which does not work with ajax) goes correctly, but the second (which works with ajax) values ​​do not pass.
<span class="syntaxdefault"><?php<br /></span><span class="syntaxkeyword">[</span><span class="syntaxdefault">i</span><span class="syntaxkeyword">]</span><span class="syntaxcomment">///data of firt form[/i]<br /></span><span class="syntaxdefault">$epoca_escolha</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">$form</span><span class="syntaxkeyword">-></span><span class="syntaxdefault">data</span><span class="syntaxkeyword">[</span><span class="syntaxstring">'escolher_epoca'</span><span class="syntaxkeyword">];</span><span class="syntaxdefault"> </span><span class="syntaxcomment">/// values of firt dropdown<br /></span><span class="syntaxdefault">$atleta_escolha</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">$form</span><span class="syntaxkeyword">-></span><span class="syntaxdefault">data</span><span class="syntaxkeyword">[</span><span class="syntaxstring">'escolher_atleta'</span><span class="syntaxkeyword">];</span><span class="syntaxdefault"> </span><span class="syntaxcomment">///values of firt dropdown<br /><br /></span><span class="syntaxdefault">echo </span><span class="syntaxstring">'Teste_epoca:'</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">$epoca_escolha</span><span class="syntaxkeyword">;</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">[</span><span class="syntaxdefault">i</span><span class="syntaxkeyword">]</span><span class="syntaxcomment">/// display values[/i]<br /></span><span class="syntaxdefault">echo </span><span class="syntaxstring">'Teste_atleta:'</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">$atleta_escolha</span><span class="syntaxkeyword">;</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">[</span><span class="syntaxdefault">i</span><span class="syntaxkeyword">]</span><span class="syntaxcomment">/// not display values[/i]<br /><br /></span><span class="syntaxkeyword">[</span><span class="syntaxdefault">i</span><span class="syntaxkeyword">]</span><span class="syntaxcomment">///data to fill the second form[/i]<br /></span><span class="syntaxdefault">$form</span><span class="syntaxkeyword">-></span><span class="syntaxdefault">data</span><span class="syntaxkeyword">[</span><span class="syntaxstring">'nome_marcas'</span><span class="syntaxkeyword">]=</span><span class="syntaxdefault">$atleta_escolha</span><span class="syntaxkeyword">;<br /></span><span class="syntaxdefault">$form</span><span class="syntaxkeyword">-></span><span class="syntaxdefault">data</span><span class="syntaxkeyword">[</span><span class="syntaxstring">'epoca_marcas'</span><span class="syntaxkeyword">]=</span><span class="syntaxdefault">$epoca_escolha</span><span class="syntaxkeyword">;<br /></span><span class="syntaxdefault">?></span>


Debugging:
Array
(
[chronoform] => marcas_registo_escolher
[event] => submit
[format] => html
[Itemid] => 993
[option] => com_chronoforms
[view] => form
[escolha_bloco] => Provas Combinadas
[escolher_epoca] => 2013_2014 // value of fist dropdown
[escolher_atleta] => /// value of the second dropdown is empty
[input_submit_201] => Escolher
[b3c9748c93559fa7a8f5742909de76cd] => 1
)

What can be happening?

Thanks

António Graça
GreyHead 02 Oct, 2013
Hi António,

I'm sorry, I've read this several times but I don't understand the question :-(

Is the second drop-down a real from element - if so it should return a value?

What is the code you have posted - I don't understand what that is doing at all?

Bob
AntonioGraca 02 Oct, 2013
Hi Bob

Sorry if I did not understand. 😶 I'll rephrase.
I have a form to choose the season (Época) and the athlete (Atleta) with two dropdown. The second drop dropdown is dependent the first dropdown. But what matters is knowing that the second dropdown works with ajax event (may be important to think about what is happening ...).

After selecting these data dropdown'll, click on buttom Choose (escolher) and load another form.
I want to pass the values ​​of the dropdown for this new form. To pass this values ​​I wrote the following code (event code costum)on load of new form.

<span class="syntaxdefault"><?php<br /></span><span class="syntaxkeyword">[</span><span class="syntaxdefault">i</span><span class="syntaxkeyword">]</span><span class="syntaxcomment">///data of firt form[/i]<br /></span><span class="syntaxdefault">$epoca_escolha</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">$form</span><span class="syntaxkeyword">-></span><span class="syntaxdefault">data</span><span class="syntaxkeyword">[</span><span class="syntaxstring">'escolher_epoca'</span><span class="syntaxkeyword">];</span><span class="syntaxdefault"> </span><span class="syntaxcomment">/// values of first dropdown of firt form<br /></span><span class="syntaxdefault">$atleta_escolha</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">$form</span><span class="syntaxkeyword">-></span><span class="syntaxdefault">data</span><span class="syntaxkeyword">[</span><span class="syntaxstring">'escolher_atleta'</span><span class="syntaxkeyword">];</span><span class="syntaxdefault"> </span><span class="syntaxcomment">///values of second dropdown of firt form<br /><br /></span><span class="syntaxdefault">echo </span><span class="syntaxstring">'Teste_epoca:'</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">$epoca_escolha</span><span class="syntaxkeyword">;</span><span class="syntaxdefault"> </span><span class="syntaxcomment">/// I test the variable and display values<br /></span><span class="syntaxdefault">echo </span><span class="syntaxstring">'Teste_atleta:'</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">$atleta_escolha</span><span class="syntaxkeyword">;</span><span class="syntaxdefault"> </span><span class="syntaxcomment">/// I test the variable and not display values<br /><br />///I send the data to fill the second form on load event (custom code)<br /></span><span class="syntaxdefault">$form</span><span class="syntaxkeyword">-></span><span class="syntaxdefault">data</span><span class="syntaxkeyword">[</span><span class="syntaxstring">'nome_marcas'</span><span class="syntaxkeyword">]=</span><span class="syntaxdefault">$atleta_escolha</span><span class="syntaxkeyword">;<br /></span><span class="syntaxdefault">$form</span><span class="syntaxkeyword">-></span><span class="syntaxdefault">data</span><span class="syntaxkeyword">[</span><span class="syntaxstring">'epoca_marcas'</span><span class="syntaxkeyword">]=</span><span class="syntaxdefault">$epoca_escolha</span><span class="syntaxkeyword">;<br /></span><span class="syntaxdefault">?><br /></span>


But the value of the second dropdown list is empty. The list of dropdown is ok, but the value do not exist. See the debugger

Debugging:
Array
(
[chronoform] => marcas_registo_escolher
[event] => submit
[format] => html
[Itemid] => 993
[option] => com_chronoforms
[view] => form
[escolha_bloco] => Provas Combinadas
[escolher_epoca] => 2013_2014 // value of fist dropdown
[escolher_atleta] => /// value of the second dropdown is empty
[input_submit_201] => Escolher
[b3c9748c93559fa7a8f5742909de76cd] => 1
)

Despite dropdown work well, the value of the second dropdown is not passed to the second form. When testing with:

echo 'Teste_epoca:'.$epoca_escolha;
echo 'Teste_atleta:'.$atleta_escolha;

the variable of value of firt dropdown have data but the variable of value of second variable is not.
Does this happen is by the second dropdown down the first form working with ajax event?

What can be happening?

Thanks

António Graça
AntonioGraca 04 Oct, 2013
Hi, Bob
Another problem (which seems to be about the same issue of dropdown which works with ajax event), the field of dropdown which is fill with ajax event not recording in the database table. Ie, the dropdown box which work with ajax, despite data I have selected is able in box, the value of field remain empty when the values ​​are sent to the database table or when I want to use these data value to pass to another form.
I checked if the name field is ok in dropdown and database table...

Suggestion?...😀

António Graça
GreyHead 04 Oct, 2013
Hi Antonio,

I can't tell anything from an image. The Debugger action is the easiest way to see what is being submitted from the form. Provided that the drop-down has valid HTML with a unique name then the value should be submitted like any other form input.

Bob
AntonioGraca 04 Oct, 2013
Hi, Bob

Thank yu for your answer.
Sorry, Bob. I dont understund

Provided that the drop-down has valid HTML with a unique name then the value should be submitted like any other form input.



can you explain m better?

António Graça
GreyHead 04 Oct, 2013
Hi Antonio,

What is the HTML for the drop-down that you see if you view the page source?

Bob
AntonioGraca 05 Oct, 2013
Hi, Bob

The code html of first dropdown one which work ok when list the result, and is possible pass the value of content
<select size="1" id="source_epocas" class="" title="" name="escolher_epoca">
<option value="">Escolha a época</option>

						<option value="2013_2014">2013_2014</option>
<option value="2012_2013">2012_2013</option>
<option value="2011_2012">2011_2012</option>
<option value="2010_2011">2010_2011</option>
<option value="2009_2010">2009_2010</option>
<option value="2008_2009">2008_2009</option>
<option value="2007_2008">2007_2008</option>
<option value="2006_2007">2006_2007</option>
						</select>

The code html of dropdown two which work ok when list the result but dont pass the value of content.
<select size="1" id="atleta_target" class="" title="" name="escolher_atleta"><option value="">Escolha o Atleta</option><option value="">Bárbara Coelho</option><option value="">Catarina Carvalho</option><option value="">Cristóvão Jorge</option><option value="">Teste</option></select>


The code help to understund the problem?Seems the same code, equal...😟

If you want try, please access to http://infortreinoapoioaotreinador.com/index.php/registo-do-rendimento.html

user: demo
pass: demo

Menu -->Marcas-->Registar Marcas
In these form have tree dropdon to choose the Bloco (block)athlete (Atleta) and the season (época). The dropdown which dont pass the valeu of content is the second, Atleta.

Thanks, Bob.

António Graça
GreyHead 05 Oct, 2013
Hi Antonio,

For some reason there are no values in the second drop-down so there is nothing to submit. See, they all have value="" :
<select size="1" id="atleta_target" class="" title="" name="escolher_atleta">
  <option value="">Escolha o Atleta</option>
  <option value="">Bárbara Coelho</option>
  <option value="">Catarina Carvalho</option>#
  <option value="">Cristóvão Jorge</option>
  <option value="">Teste</option>
</select>

Bob
AntonioGraca 05 Oct, 2013
Hi, bob
Thks again
Which possible reason to hapen this ?


Thanks
GreyHead 06 Oct, 2013
Hi Antonio,

Something is not correct in the Ajax event code. All that is being passed back to the form is e.g. =Escolha o Atleta

Bob
AntonioGraca 07 Oct, 2013
Hi, Bob
You were right. The code in the ajax event was wrong. There were six hypotheses of code to get to the listing in the second dropdown but only one of them was correct for listing the names and assumed values ​to dropdown ​​and could pass the values to the other form.
Ps. Sorry for the time you spent

Thks for your support :mrgreen:

António Graça
This topic is locked and no more replies can be posted.