1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Rep Power

    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

    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)

    <script type="text/javascript"> 
    addpage = function(){ document.jax.offset.value = document.jax.offset.value*1 + 15 ; 
    return true;}
    <script type="text/javascript"> 
    backpage = function(){ document.jax.offset.value = document.jax.offset.value*1 - 15 ; 
    return true;}
    my javascript file which passes the variables

    jQuery(document).ready(function() {
        var link = jQuery("#link").val();
        var player = jQuery("#player").val();
        var offset = jQuery("#offset").val();		
                type: 'POST',
                url: '/wordpress/wp-admin/admin-ajax.php',
                data: {
                    action: 'sfunction',
                    link: link,
    		player: player,
    		offset: offset,
                success: function(data, textStatus, XMLHttpRequest){
                error: function(MLHttpRequest, textStatus, 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
  2. #2
  3. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Rep Power

    2 small notes:

    1) Please post a thread on only one board; if it's posted in the wrong spot, it can be moved to the right one.

    2) Java and JavaScript are not the same programming language; they are not actually even remotely related.

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around

IMN logo majestic logo threadwatch logo seochat tools logo