Welcome Guest, Not a member yet? Register   Sign In
div onclick


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

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

It does nothing at all.

Any ideas?

[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.

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)

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

frietkot use site_url instead.

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:


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

Theme © iAndrew 2016 - Forum software by © MyBB