admin管理员组文章数量:1335371
<input type="checkbox" name="checket" id="checket" />
$url = 'test';
and when i check it i want it to go to a url: href='$url'
and remember that has been checked.
any ideas?
thanks
edit: maybe
if ($('#checket:checked').val() !== undefined) {
// Insert code here. }
<input type="checkbox" name="checket" id="checket" />
$url = 'test.';
and when i check it i want it to go to a url: href='$url'
and remember that has been checked.
any ideas?
thanks
edit: maybe
if ($('#checket:checked').val() !== undefined) {
// Insert code here. }
Share Improve this question edited May 16, 2011 at 21:33 user680786 asked May 16, 2011 at 21:22 PatrioticcowPatrioticcow 27.1k76 gold badges221 silver badges339 bronze badges 4- 2 PHP is a server side only language. It can generate your page, but can't make it dynamic. You'll have to use javascript for that – Riccardo Galli Commented May 16, 2011 at 21:26
- Your question is too vague. If you want to to happen the moment you check the box, that has to be done through JavaScript. If you want it to simply be remembered when you submit the form, that's an easy enough thing to handle in the PHP, and I don't see the need to step you through that. – Andrew Commented May 16, 2011 at 21:26
- Use javascript for client side scripting – Ibu Commented May 16, 2011 at 21:27
- Your question is not clear enough. You want to remember which option has been checked? At what point? do you want the new page to know about the selection or do you want the previous page to remember if the user access it again? is the user submitting the page? or do you want the page to go to a new address once the checkbox has been clicked? please specify more.... – Hanan Commented May 16, 2011 at 21:28
5 Answers
Reset to default 6Without using a JS library like jquery or mootools, here's how to do it in barebones JS:
<input
type="checkbox"
value="<?php echo htmlspecialchars($url) ?>"
name="checket"
onClick="if (this.checked) { window.location = this.value; }"
/>
Note that I've split the tag across multiple lines so it's easier to read. basically, embed the desired url into the checkbox's value field, then put an onclick handler that'll read out that URL and feed it to window.location when the checkbox bees checked.
Load the jquery library and then use the following code:
$('input[type=checkbox]#checket').click(function() {
if($(this).is(':checked')) {
$.get('urlhere', function(data) {
// Process return data here
});
}
});
The way I see it you have a couple options.
1) Open the link in a new window using javascript and an onclick
http://wpcult./open-external-links-in-a-new-window/
2) Set a cookie that stores the data and check for the existence of the cookie
http://www.w3schools./php/php_cookies.asp
3) Store the data in the session variable
http://www.w3schools./php/php_sessions.asp
If you have more than one checkbox, put the URL in the value of the checkbox and add a class to all the checkboxes you want to do this:
<input type="checkbox" name="checket" id="checket" class="checkedurl" value="<?=$url?>" />
<script type="text/javascript">
$(document).ready(function(){
$('input.checkedurl').click(function() {
if ($(this).is(':checked')) {
var checkurl = $(this).val();
var postvars = "url="+checkurl;
$.ajax({
url: "scripttostore.php",
type: 'post',
data: postvars,
cache: false,
success: function () {
location.href = checkurl;
}
});
}
});
</script>
If it's all checkboxes on the page you don't have to use the class, you could just use $('input[type=checkbox]')
The scripttostore.php would be what you use to store the url information.
you can only do it on the client side
<input type="checkbox" name="checket" id="checket" onclick="location.href='test.'"/>
本文标签: javascriptphphow to run a link when check box checkedStack Overflow
版权声明:本文标题:javascript - php, how to run a link when check box checked? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742381191a2464125.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论