javascript - Return variable in an onclick function -


i have javascript code returns variable called foo

i need pass variable text onclick function

function getqueryvariable(variable)  {         var query = window.location.search.substring(1);         var vars = query.split("&");         (var i=0;i<vars.length;i++) {                 var pair = vars[i].split("=");                 if(pair[0] == variable){return pair[1];}         }         return(false);  }    var foo = getqueryvariable("dv1");
<ul class="answer-list">  	<li><a class="btn rollover" onclick="nextquestion(6, 'http://www.example.net/iclk/redirect.php?apxcode=042004&id=et9hmn9xd3xmgt8nkuj0krjmiwuxetj0kn2-0n&dv1=foohere');"><span>yes</span></a></li>  	<li><a class="btn rollover" onclick="nextquestion(6, 'http://www.example.net/iclk/redirect.php?apxcode=042004&id=et9hmn9xd3xmgt8nkuj0krjmiwuxetj0kn2-0n&dv1=foohere');"><span>no</span></a></li>  </ul>

i need know how pass variable foo onclick function link in place of foohere.

how in order correct link ?

you can call function 2 parameters, , function call nextquestion

html:

<ul class="answer-list">     <li><a class="btn rollover" onclick="somefunc(6, 'http://www.example.net/iclk/redirect.php?apxcode=042004&id=et9hmn9xd3xmgt8nkuj0krjmiwuxetj0kn2-0n&dv1=');"><span>yes</span></a></li>     <li><a class="btn rollover" onclick="somefunc(6, 'http://www.example.net/iclk/redirect.php?apxcode=042004&id=et9hmn9xd3xmgt8nkuj0krjmiwuxetj0kn2-0n&dv1=');"><span>no</span></a></li> </ul> 

javascript:

function getqueryvariable(variable) {        var query = window.location.search.substring(1);        var vars = query.split("&");        (var i=0;i<vars.length;i++) {                var pair = vars[i].split("=");                if(pair[0] == variable){return pair[1];}        }        return(false); }  function somefunc(number, link) {     link = link + getqueryvariable("dv1");     nextquestion(number, link ) } 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -