jquery - manipulate request string dynamically with javascript -


i have request link:

<a href=index.jsp></>

and have divs in part of page, contain values , change user or under conditions:

<input id="var1" /> <input id="var2" />

how can update dynamically url have inside value of these 2 vars, resulting in

<a href=index.jsp?var1=1&var2=17></>

is there easy javascript/jquery way, or, html way perhaps?

var val1 = $('#var1').val(),     val2 = $('#var2').val();   $('a').attr('href', function(i, src) {      return src+ '?var1=' + val1 + '&var2=' + val2 ;   }); 

use correct selector select element . set href of anchor , appending querystring parameters it.

if want change in particular event need listen event , perform same actions.

the same can written way can easier understand.

 var val1 = $('#var1').val(),      val2 = $('#var2').val();       var src = $('a').attr('href');  // current href      var newsrc = src+ '?var1=' + val1 + '&var2=' + val2 ;       $('a').attr('href', src); // set href 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -