0

I am trying to pass a value to a static HTML page. jQuery finds the value in the table, but how do I pass it to the next page

$('.gobutton').bind('click', function(){
   var value = $(this).closest('tr').find('td')[0].innerHTML        
   var forward = window.location.replace('{% url 'example' %}');
});

I tried using sessionStorage.setItem("user_val",value) but I cant seem to recover it on that view in any way.

$.post('{% url 'example' %}', {"user_val":value}) method doesn't load the html page, but passes the value.

rodling
  • 988
  • 5
  • 18
  • 44
  • http://stackoverflow.com/questions/19925711/how-to-pass-value-to-another-static-page-via-javascript – Derple Apr 19 '14 at 16:44

2 Answers2

0

create a form with a hidden input field, populate the hidden input field with your value. Bind click event to form submit and then just read the POST variable.

Vickel
  • 7,879
  • 6
  • 35
  • 56
  • Sample code? It is not as easy as one button, I have many of them and they extract a value from the table and then submit it – rodling Apr 19 '14 at 16:45
  • they are dynamically populated, id rather stay way from unique id buttons here – rodling Apr 19 '14 at 16:54
  • if you create dynamically (e.g. populate from a database) you have already a unique id you could use – Vickel Apr 19 '14 at 17:03
0

Ended up doing

sessionStorage.setItem("user_val",value);
window.location.replace('{% url 'example' %}');

Then on example page I checked for existence of user_val with sessionStorage.getItem If user_val existed I launched the coded (AJAX) I need. And set user_val to "", cleaning up the memory. If user_val didnt exist it would launch the page like it was previously.

rodling
  • 988
  • 5
  • 18
  • 44