var studno = $('#studno').val();
$(document).ready(function () {
$('.go').click(function () {
$('.inup').load('prochat.php', {
studno: studno
});
});
});
I have this code and it's supposed to send the value of studno into prochat.php but everytime it does it only says undefined. Can anyone explain?
Try this:
$(document).ready(function(){
$('.go').click(function(){
var studno = $('#studno').val();
$('.inup').load('prochat.php', {studno:studno});
});
});
Try this:
$(document).ready(function(){
$('.go').click(function(){
var studno = $('#studno').val();
$('.inup').load('prochat.php', {studno:studno});
});
});
Never mind. Turns out this works
$('.inup').load('prochat.php', {studno: $('#studno').val()});
These could be possible reasons:
at the line where you are assigning the value to studno, the value of studno might be undefined
#studno is not defined in the html
possible solutions:
-. try assigning the value within the click function:
like this:
$('.go').click(function(){
studno = $('#studno').val();
$('.inup').load('prochat.php', {studno:studno});
});
-. make sure that the element with id studno exists in the html document
This should work better:
$(document).ready(function () {
$('.go').click(function () {
$('.inup').load('prochat.php', {
studno: $('#studno').val()
});
});
});
Related
I am trying to create a session in php every time a checkbox is selected. i have got this working on each individual check box using the following:
onchange="$.get(\'set_item.php?stockID='.$row[stockID].'&push=\'+this.checked);"
I now would like to add a check all link which then selects all of the check boxes and then actions the above line to create the php session... so far i have got the check all link working but i can not get the loop to work.
$(document).ready(function () {
$('#selectChb').click(function(){
$(':checkbox').prop("checked", true);
});
$(":checkbox:checked").each(function() {
str = this.val();
$.get('set_item.php?stockID='+str+'&push='+this.checked);
});
$(":checkbox:not(:checked)").each(function() {
str = this.val();
$.get('set_item.php?stockID='+str+'&push='+this.checked);
});
});
This should allow you to also remove the inline onchange that you have on your checkbox elements.
$(document).ready(function () {
$('#selectChb').click(function(){
$(':checkbox').prop("checked", true);
});
$(":checkbox").on("change", function() {
if($(this).is(":checked"))
{
str = $(this).val();
$.get('set_item.php?stockID='+str+'&push='+this.checked);
}
});
});
I have a php page with jQuery, with range sliders.
When the sliders are changed the jQuery code sums the values.
I also want this code to be fired when the page is loaded. But it doesn't happen when I trigger the function inside $(window).load(function() {}); or directly in $(document).ready(function() {});.
Here's the jQuery code:
$(document).ready(function() {
$(window).load(function() {
countSilders();
});
function countSliders(){
var SliderValue = parseInt($("#slider0").val())+parseInt($("#slider1").val())+parseInt($("#slider2").val());
if (SliderValue==10)
$("#submit_next").button("enable");
else
$("#submit_next").button("disable");
$("#lblsum_scores").text(SliderValue+"/10");
}
$(document).on("change","#sliders", function(){
countSliders();
});
});
Try this:
// First define your function
function countSliders() {
var SliderValue = parseInt($("#slider0").val()) + parseInt($("#slider1").val()) + parseInt($("#slider2").val());
if (SliderValue == 10) $("#submit_next").button("enable");
else $("#submit_next").button("disable");
$("#lblsum_scores").text(SliderValue + "/10");
}
// Run on ready, don't use ready and then on load, that will never happen
// And i changed the on() to change()
$(document).ready(function(){
countSilders();
$("#sliders").change(function(){
countSliders();
});
});
You should be able to do:
function countSliders(){
...
}
$(document).ready(function() {
countSilders(); // fire it on load
// bind it to sliders
$(document).on("change","#sliders", function(){
countSliders();
});
});
I have a link that opens a modal when clicked, however that element also has a data-id="#id here" attribute that I need to grab so I can pass it to my php script for processing. How can I accomplish this?
My JS code:
$(document).ready(function() {
$('#edit_general').click(editModal);
});
function editModal(event)
{
var modal = $('#editModal');
modal.modal({
show: true
});
}
My html:
<li><a id="edit_general" href="#editModal" data-uid="<?php echo $u->id; ?>">Edit General</a></li>
I tried using the this keyword but it didn't work.
How can I accomplish this?
Try this: Demo http://jsfiddle.net/szS2J/1/ or http://jsfiddle.net/ug7ze/
$(this).data('uid')
Hope it fits the cause :)
like this:
$('#edit_general').click(editModal);
$(this).data('uid')
full
$(document).ready(function() {
$('#edit_general').click(editModal);
});
function editModal(event) {
alert($(this).data('uid'));
var modal = $('#editModal');
modal.modal({
show: true
});
}
You can get the value using the attr method: $(this).attr('data-uid')
Like this stored in data_id.
$(document).ready(function() {
$('#edit_general').click(function() {
var data_id = $(this).data('uid');
var modal = $('#editModal');
modal.modal({
show: true
});
});
});
I'm not sure why i can' t get my output to surface. It shouldn't be too hard but has been stuck for several hours. All i
<script>
$(document).ready(function(){
$('#chat_submit').click(function(){
var data="{'chat_content:'+$('#chat_content').val()+'chat_from_who:'+$('#chat_from_who').val()+'chat_to_who:'+$('#chat_from_who').val()+'order_no:'+$('#order_no').val()}";
$('#order_chatbox').load('/seller/helpers/order_chat.php',data);
});
});
</script>
Any help here will be greatly appreciated.
You are sending the data as a long string.. not as an object.
Change it to
var data= {'chat_content': $('#chat_content').val(),
'chat_from_who': $('#chat_from_who').val(),
'chat_to_who': $('#chat_from_who').val(),
'order_no': $('#order_no').val()};
Try the following:
$(document).ready(function() {
$('#chat_submit').click(function(event) {
// event.preventDefault();
var data = {
chat_content: $('#chat_content').val(),
chat_from_who: $('#chat_from_who').val(),
chat_to_who: $('#chat_from_who').val(),
order_no: $('#order_no').val()
};
$('#order_chatbox').load('/seller/helpers/order_chat.php', data);
});
});
why my code is not working? I have called a javascript function after page load PHP script.like below:
<script>
setTimeout("fb_login()",100);
</script>
fb_login() function is on same page
function fb_login()
{
alert("ok");
}
Tried with setTimeout("fb_login",100); too. but not working.
I have checked console, but it's giving no error.
Just change it to:
<script>
setTimeout(fb_login, 100);
</script>
Change this code:
<script>
setTimeout("fb_login()",100);
</script>
to this:
<script>
setTimeout(fb_login,100);
</script>
Good explanation from similar post - How can I pass a parameter to a setTimeout() callback?
It might be you given less time in setTimeout but and it's calling your function befor page loaded fully. So Try to increase time.
<script>
setTimeout("fb_login()",1000);
</script>
Make sure that fb_login is being initialized before calling otherwise it will give error. Either use document.ready or add that function before it is called. Does it give you some error like "fb_login is undefined" ?
try this
<script>
window.onload = function(){
setTimeout(fb_login,100);
};
function fb_login(){
alert("ok");
}
</script>
EDIT: first check if the below is working or not, if it does not work then pbm is somewhere else
window.onload = function(){
setTimeout(function(){
fb_login();
},100);
};