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

[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?
#2

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

[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)
#4

[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,.
#5

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

[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'"




Theme © iAndrew 2016 - Forum software by © MyBB