2

I am working on online shopping website like flipkart and want to forward values through request or say just want to append value to URL, But I have not used form so, I can not use form action. For instance consider following situation.

value1<input type="number" min="1" name="value1">
         <a href="somePage.jsp">value1</a>

          value2<input type="number" min="1" name="value2">
         <a href="somePage.jsp">value2</a>

          value3<input type="number" min="1" name="value3">
         <a href="somePage.jsp">value3</a>

I have three input text associated with three hyper link and if I hit any link then value in respective text-box should appended to URL and we go to next page. In this case somePage.jsp?Value=2 something like this....

Nishi
  • 10,105
  • 3
  • 24
  • 35
Atish Kumbhar
  • 361
  • 6
  • 16

3 Answers3

2

HTML

<a id="reflectedlink" href="http://www.google.com/search">http://www.google.com/search</a>

I will show you with an example, here on keyup event i am dynamically changing href value.

JAVASCRIPT

<script type="text/javascript">
    var link= document.getElementById('reflectedlink');
    var input= document.getElementById('searchterm');
input.onchange=input.onkeyup= function() {
    link.search= '?q='+encodeURIComponent(input.value);
    link.firstChild.data= link.href;
};

Check the same in https://jsfiddle.net/aadi/pr5j9Lbv/

Naruto
  • 3,847
  • 1
  • 18
  • 30
  • If this solved your problem, please don't forgot to upvote and mark it as solved. This will help others looking for similar problem – Naruto Mar 27 '16 at 20:02
1

You can change the content of the href attribute via JavaScript, as described here.

Community
  • 1
  • 1
André
  • 1,732
  • 1
  • 21
  • 24
0

thanks André I have got my mistake. the problem is solved by your solution, But I have made mistake is I am given same name for all the links....

Atish Kumbhar
  • 361
  • 6
  • 16