CodeIgniter Forums
Simpel Question (anchor + js) - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forum-22.html)
+--- Thread: Simpel Question (anchor + js) (/thread-51541.html)



Simpel Question (anchor + js) - El Forum - 05-08-2012

[eluser]Dizza[/eluser]
Hey there,

I think the answer to this question is quite simple.

I want to get the value of my form_dropdown with jQuery when the form is submitted.
The value will be passed to the url so i can get the ID on the next page out of the url.

The thing is that i dont know how i can add javascript to the anchor tag.


The Dropdown has an ID which i select with jQuery to get the value
Code:
&lt;?php echo "<br />"; echo form_dropdown('klasdropdown', $klasdropdown, '', 'id="test"' ); ?&gt;

The jQuery code is as follows:
Code:
$('select#test').val();

And the anchor
Code:
&lt;?php echo anchor('aanwezigheid/formulier/' . "I WANT THE VALUE OFF THE DROPDOWN HERE" . '', 'ga');?&gt;

Now my question, how can i get the output of the jquery into the anchor?

I searched but didn't find anything which solves my problem

Thanks already Big Grin



Simpel Question (anchor + js) - El Forum - 05-08-2012

[eluser]kanjimaster[/eluser]
I guess you could use jQuery to update the anchor's href attribute when the value of the dropdown changes, but why not just use a submit button for the form instead of an anchor, so that the data is passed in the normal way?


Simpel Question (anchor + js) - El Forum - 05-08-2012

[eluser]Dizza[/eluser]
[quote author="kanjimaster" date="1336508265"]I guess you could use jQuery to update the anchor's href attribute when the value of the dropdown changes, but why not just use a submit button for the form instead of an anchor, so that the data is passed in the normal way?[/quote]

But how do i get the value from the dropdown then?
If i do it like this
Code:
&lt;?php echo form_open('aanwezigheid/formulier/'.$klasdropdown['id'].''); ?&gt;


&lt;?php echo "<br />"; echo form_dropdown('klasdropdown', $klasdropdown, ''); ?&gt;
&lt;?php echo form_submit('submit', 'Voeg klas toe'); ?&gt;

the url output is:
Code:
http://afstuderen.dev/index.php/aanwezigheid/formulier/Array

The array should be the id of the selected option Sad


Simpel Question (anchor + js) - El Forum - 05-08-2012

[eluser]kanjimaster[/eluser]
If the form is submitted in the normal way the dropdown value will be waiting for you in $this->input->post('klasdropdown').