JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 16th, 2013, 01:42 PM
scottish_jason scottish_jason is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 5 scottish_jason User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 41 m 3 sec
Reputation Power: 0
Updating hidden field with javascript for posting

Hi guys,

im trying to send hidden field value's using ajax so that I dont need to refresh the page. I do have this functionality working but one of my variables requires to be updated every time that I press the "next page" link (offset +15)

I found some javascript code which apparently should be able to achieve this. The javascript variable does update (itterates +15 on link click - verified by doing an alert(document.jax.offset.value) but the hidden field value does not pass the updated value when posted.

any idea's guys?

My hidden form code

Code:
echo '<form id="jax" name="jax" method="post">';
echo '<input type="hidden" id="player" value="'.$player.'"></input>';
echo '<input type="hidden" id="link" value="'.$link.'"></input>'; 
echo '<input type="hidden" id="genre" value="'.$genre.'"></input>';
echo '<input type="hidden" id="offset" name="offset" value="0"></input>';
echo '<a href="#" id="back" onclick="backpage()" >Back</a>';
echo '<a href="#" id="forward" onclick="addpage()">Forward</a><<br>';
echo '</form>';


javascript functions to add 15 & subract 15 to the offset hidden field ( back + add links)

Code:
<script type="text/javascript"> 
addpage = function(){ document.jax.offset.value = document.jax.offset.value*1 + 15 ; 
return true;}
</script>

<script type="text/javascript"> 
backpage = function(){ document.jax.offset.value = document.jax.offset.value*1 - 15 ; 
return true;}
</script>


my javascript file which passes the variables


Code:
jQuery(document).ready(function() {
    var link = jQuery("#link").val();
    var player = jQuery("#player").val();
    var offset = jQuery("#offset").val();		
    jQuery("#forward").click(function(){

        jQuery.ajax({
            type: 'POST',
            url: '/wordpress/wp-admin/admin-ajax.php',
            data: {
                action: 'sfunction',
                link: link,
		player: player,
		offset: offset,
		
            },
            success: function(data, textStatus, XMLHttpRequest){
                jQuery("#div").html('');
                jQuery("#div").append(data);
            },
            error: function(MLHttpRequest, textStatus, errorThrown){
                alert(errorThrown);
            }
        });
    });
});


any idea's guys? as I said all the variables do pass over but the "offset" value is always passed over as "0" even though the local javascript variables does indeed increment when the "addpage" link is clicked

Reply With Quote
  #2  
Old February 16th, 2013, 09:56 PM
web_loone08's Avatar
web_loone08 web_loone08 is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2008
Posts: 605 web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 16 h 30 m 44 sec
Reputation Power: 69
Try putting your input value variables inside the jQuery("#forward") function. It looks like those variables are just outside the scope of that function. I maybe wrong, but test it and see.

Code:
jQuery(document).ready(function() {	
	
    jQuery("#forward").click(function(){

    var link = jQuery("#link").val();
    var player = jQuery("#player").val();
    var offset = jQuery("#offset").val();

// proceeding function below...

Reply With Quote
  #3  
Old February 17th, 2013, 11:25 AM
scottish_jason scottish_jason is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 5 scottish_jason User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 41 m 3 sec
Reputation Power: 0
do you mean like this?

Code:
<script type="text/javascript"> 
var offset = jQuery("#offset").val();
addpage = function(){ document.jax.offset.value = document.jax.offset.value*1 + 15 ; 
return true;}
</script>

<script type="text/javascript"> 
var offset = jQuery("#offset").val();
backpage = function(){ document.jax.offset.value = document.jax.offset.value*1 - 15 ; 
return true;}
</script>


I tried that and it never worked

Reply With Quote
  #4  
Old February 17th, 2013, 09:24 PM
web_loone08's Avatar
web_loone08 web_loone08 is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2008
Posts: 605 web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 16 h 30 m 44 sec
Reputation Power: 69
Quote:
Originally Posted by scottish_jason
do you mean like this?

Code:
<script type="text/javascript"> 
var offset = jQuery("#offset").val();
addpage = function(){ document.jax.offset.value = document.jax.offset.value*1 + 15 ; 
return true;}
</script>

<script type="text/javascript"> 
var offset = jQuery("#offset").val();
backpage = function(){ document.jax.offset.value = document.jax.offset.value*1 - 15 ; 
return true;}
</script>


I tried that and it never worked


Uhhh... no; like this:

Code:
jQuery(document).ready(function() {
		
    jQuery("#forward").click(function(){

    var link = jQuery("#link").val();
    var player = jQuery("#player").val();
    var offset = jQuery("#offset").val();

        jQuery.ajax({
            type: 'POST',
            url: '/wordpress/wp-admin/admin-ajax.php',
            data: {
                action: 'sfunction',
                link: link,
		player: player,
		offset: offset,
		
            },
            success: function(data, textStatus, XMLHttpRequest){
                jQuery("#div").html('');
                jQuery("#div").append(data);
            },
            error: function(MLHttpRequest, textStatus, errorThrown){
                alert(errorThrown);
            }
        });
    });
});

Reply With Quote
  #5  
Old February 17th, 2013, 10:10 PM
scottish_jason scottish_jason is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 5 scottish_jason User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 41 m 3 sec
Reputation Power: 0
Quote:
Originally Posted by web_loone08
Uhhh... no; like this:

Code:
jQuery(document).ready(function() {
		
    jQuery("#forward").click(function(){

    var link = jQuery("#link").val();
    var player = jQuery("#player").val();
    var offset = jQuery("#offset").val();

        jQuery.ajax({
            type: 'POST',
            url: '/wordpress/wp-admin/admin-ajax.php',
            data: {
                action: 'sfunction',
                link: link,
		player: player,
		offset: offset,
		
            },
            success: function(data, textStatus, XMLHttpRequest){
                jQuery("#div").html('');
                jQuery("#div").append(data);
            },
            error: function(MLHttpRequest, textStatus, errorThrown){
                alert(errorThrown);
            }
        });
    });
});


thanks for the help, but unfortunately that never worked. As i was saying, all of the values pass over fine, its just that the updated value (from the addpage/backpage function) does not pass over even though the local javascript variable does indeed update.

Reply With Quote
  #6  
Old February 18th, 2013, 12:14 AM
scottish_jason scottish_jason is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 5 scottish_jason User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 41 m 3 sec
Reputation Power: 0
Quote:
Originally Posted by scottish_jason
thanks for the help, but unfortunately that never worked. As i was saying, all of the values pass over fine, its just that the updated value (from the addpage/backpage function) does not pass over even though the local javascript variable does indeed update.


sorry never mind, I got it

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > Updating hidden field with javascript for posting

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap