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
Post a Comment