CodeIgniter Forums
div onclick - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: div onclick (/showthread.php?tid=12180)



div onclick - El Forum - 10-09-2008

[eluser]frietkot[/eluser]
Hi,

I have a div and I want to use onClick on it.
Normally it just works fine, but not with codeigniter.

Code:
onClick='window. location.href="<?=anchor('test', 'test')?>;"'

It does nothing at all.

Any ideas?


div onclick - El Forum - 10-09-2008

[eluser]GSV Sleeper Service[/eluser]
is that your example code? if so, it does nothing because there's no onclick code there!
really you should be using jquery or prototype.js and using unobtrusive javascript.
I have used clickable divs a lot in codeigniter and never had any problems

[edit] your example code changed.


div onclick - El Forum - 10-09-2008

[eluser]frietkot[/eluser]
I think it's a problem with the anchor helper
Without it it just works, with it not.

(btw I put an space between window and location because the forum didn't show the snippet without the space)


div onclick - El Forum - 10-09-2008

[eluser]GSV Sleeper Service[/eluser]
ah, yes. the anchor helper will create an href tag.
so your code would look like
Code:
onClick='window. location.href="<a href="test">test</a>"'
which explains why it's not working,.


div onclick - El Forum - 10-09-2008

[eluser]xwero[/eluser]
frietkot use site_url instead.


div onclick - El Forum - 10-09-2008

[eluser]jcopling[/eluser]
Given the code example that you have provided, you would be setting the URL to something like:

http://<a href="test">test</a>

Which is not the desired effect.
You would want to product something like:

http://yourdomain.com/test

You can achieve this with the following code:
Code:
onClick="window .location .href='&lt;?= base_url();?&gt;/test'"