0
<script language=JavaScript>

function add()
 {

***Z***=3025;
}
</script>
<form........>
<input type ="submit" onClick="add()"
</form>

<a herf="http://XXXXXXXX.co.uk/XXXX.qmd?pack_id=***Z***"></a>

need to put the Z***emphasized text*** value in the URL The value of z will be produce by another java script function ADD

Jan Hančič
  • 49,796
  • 15
  • 87
  • 97
Deabjyoti
  • 11
  • 1
  • 2

2 Answers2

0

You want to set the value of Z in the add() function and pass that value to the querystring in the URL. I assume you want a client side implementation here.

It wont work that way because the variable Z is not recognized outside the <script> block, so the <A href> does not know of such a variable.

What will work however, is if you create the whole URL within the function and submit it from within the function.

Your code will look like this:

In the add() function, the URL is constructed and browser address is instantly changed to that location.

<script>
function add()         { 

var Z="3025"; 
document.location="http://XXXXXXXX.co.uk/XXXX.qmd?pack_id="+Z;
} 
</script> 
<form> 
    <input type ="submit" onClick="javascript:add()" value="my button"> 
    </form>

If you actually want to just set the variables into the <A href> so that these can be clicked by the user at a later time, you'll probably need to use some not recommended techniques such as document.write of the full url.

Read the above link for why not to go down that route.

Community
  • 1
  • 1
JoseK
  • 30,355
  • 14
  • 98
  • 129
0

The best would be generating this at the server side, so that html is ready and no manipulation in JavaScript is needed. However:

give id to your link:

<a href="http://XXXXXXXX.co.uk/XXXX.qmd?pack_id=" id="cool_link"></a>

and change its href attribute:

<script>
    var Z = 3025;
    document.getElementById("cool_link").href += "***" + Z + "***";
</script>

if you're using jQuery syntax may be simplified a bit.

dmitko
  • 2,539
  • 2
  • 19
  • 15