Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-16-2013, 10:40 AM   PM User | #1
scottish_jason
New to the CF scene

 
Join Date: Feb 2013
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
scottish_jason is an unknown quantity at this point
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

Last edited by scottish_jason; 02-16-2013 at 07:06 PM..
scottish_jason is offline   Reply With Quote
Old 02-16-2013, 02:22 PM   PM User | #2
Airblader
Regular Coder

 
Join Date: Jan 2013
Location: Germany
Posts: 354
Thanks: 3
Thanked 43 Times in 43 Posts
Airblader can only hope to improve
What exactly are you gonna do if someone just decides to open his browser's development tools and change the values for the hidden fields?

Last edited by Airblader; 02-16-2013 at 02:25 PM..
Airblader is online now   Reply With Quote
Old 02-16-2013, 06:49 PM   PM User | #3
scottish_jason
New to the CF scene

 
Join Date: Feb 2013
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
scottish_jason is an unknown quantity at this point
Quote:
Originally Posted by Airblader View Post
What exactly are you gonna do if someone just decides to open his browser's development tools and change the values for the hidden fields?
they will get a certain page of results? I fail to see the problem.
How exactly should I handle this?
scottish_jason is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:57 PM.


Advertisement
Log in to turn off these ads.