homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

Creating HREF with Java
Help with a dynamic link
Scott Archer

Msg#: 4507120 posted 11:08 pm on Oct 11, 2012 (gmt 0)

I need to pull two totals out of a web page that is JAVA driven.

here is one:

<tr><td class="auto-style21" style="width: 616px">
Total one time set up cost:</td>
<td class="auto-style21">
<input name="Text22" id="text22" type="text" value="$" readonly="readonly"></td></tr>

And I need to insert it into:

https://www.targetsite.com/amp;a1=TOTAL GOES HERE;">

Any Ideas?




WebmasterWorld Senior Member lucy24 us a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month

Msg#: 4507120 posted 12:01 am on Oct 12, 2012 (gmt 0)

Do you mean java or javascript? Not really important, because anything you can do in one language you can do in another; you just need to tweak the punctuation a bit ;)

In javascript you'd do it with ID's. Each thing that you're pulling text out of has an ID-- unless you've already retrieved it by other means-- and the thing you're putting text into has an ID. For example (note capitalization of "Id" because a mistake here will kill the whole code, 87,000 guesses how I know this)

mystring = document.getElementById("your-id-here").value

where "value" sounds as if it means "numerical equivalent" but really just means "whatever its content is". If there isn't already code to make sure that your input resolves to an appropriately formatted number, you'll need to do a quick test. After that, you're doing exactly the same thing as

:: insert boilerplate about yawn-provoking coincidence ::

something I posted about less than 24 hours ago.

output = "https://www.example.com/amp;a1=" + mystring

and then plug the "output" variable back into your code using innerHTML or whatever is most appropriate. Can I assume that when you say "amp;" you mean "&amp;"? Or do you really mean "?" (literal question mark)?


WebmasterWorld Senior Member 5+ Year Member

Msg#: 4507120 posted 4:57 am on Oct 12, 2012 (gmt 0)

Assuming URL within link tag, put onclick method on link to calculate it just in time may be best bet.

Alternatively fix up whatever URL is part of, each time input changes, make initial URL consistent with initial input value.

Scott Archer

Msg#: 4507120 posted 2:24 pm on Oct 12, 2012 (gmt 0)

I guess I am not explaining the problem very well, and I apologize for that. My challenge is that I am over my head a bit here so I am not be using the right terms.

I have managed to put together an order page where the math is being handled by Java.

Ultimately I end up with to sums at the bottom of the page. These two sums need to be transferred to my PayPal merchant account in a specific <a href> of their creation.

and it looks like this:

<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_xclick-subscriptions&amp;business=xxxxxxxxxxxx&amp;lc=US&amp;item_name=Auto%20Proxy%20Posting&amp;no_note=1&amp;no_shipping=2&amp;a1=COST-ONE%2e00&amp;p1=1&amp;t1=M&amp;src=1&amp;a3=COST-TWO%2e11&amp;p3=1&amp;t3=M&amp;currency_code=USD&amp;bn=PP%2dSubscriptionsBF%3abtn_subscrib">

So I need to break this up into five elements and reassembly it with COST-ONE & COST-TWO replaced in the string with my two java values - which are expressed as:

<input name="Text22" id="text22" type="text" value="$" readonly="readonly">


<input name="Text23" id="text23" type="text" value="$" readonly="readonly">

So you see I cant just have an anchor with a +n+ that tags onto the end.

If I use

var na = document.getElementById("text22").value;

I don't get the whole string I need.

I cant seem to find anything on line as an example of this type of assemblyman and so I am stuck. I am not a scriptwriter just a good mimic,and can't find examples to work from.

Can you help?

Scott Archer

Msg#: 4507120 posted 5:34 pm on Oct 12, 2012 (gmt 0)

I think I am on to the solution but something in this is not quite right...


in the body I am pulling the vale of these two lines:

<input name="Text22" id="text22" type="text" value="$" readonly="readonly"></td>
<input name="Text23" id="text23" type="text" value="$" readonly="readonly"></td>

here is where I am at:

<script language="javascript" type="text/javascript">
function urlGen(f){
var i1 = "https://www.paypal.com/cgi-bin/webscr?cmd=_xclick-subscriptions&amp;business=xxxxxxxxxxxx&amp;lc=US&amp;item_name=A%20P%20P&amp;no_note=1&amp;no_shipping=2&amp;a1=";
var i2 = f.text22.value;
var i3 = "&amp;p1=1&amp;t1=M&amp;src=1&amp;a3=";
var i4 = f.text23.value;
var i5 = "&amp;p3=1&amp;t3=M&amp;currency_code=USD&amp;bn=PP%2dSubscriptionsBF%3abtn_subscrib";
var fullURL = i1 + i2 + i3 +i4 + i5;
f.action = i1 + i2 + i3 + i4 + i5;
return true;


<a href="javascript: void(0)" onclick="scriptFunction(f.action)" target="_blank">
<div id="submit" class="out"
onMouseOver="document.getElementById('submit').className = 'over';"
onMouseOut="document.getElementById('submit').className = 'out';">


WebmasterWorld Senior Member lucy24 us a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month

Msg#: 4507120 posted 11:54 pm on Oct 12, 2012 (gmt 0)

I cant just have an anchor with a +n+

It doesn't have to stop there. That was just the starting example. In javaSCRIPT-- which seems to be what we're talking about-- you can happily do

mystring = 'somefixedtext' + variable1 + 'morefixedtext' + variable2 + 'stillmorefixedtext'

et cetera until the cows come home. Your variables can come from anywhere: pulled directly from inputs, or from the result of calculations, or something global that you've previously generated, et cetera again.

And once you've assembled the entire '<a href = "blablabla">anchortext</a>' package, you shove it into place.

Scott Archer

Msg#: 4507120 posted 3:20 pm on Oct 13, 2012 (gmt 0)

can you show me an actual example of the mystring and it being used?


WebmasterWorld Senior Member lucy24 us a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month

Msg#: 4507120 posted 1:53 am on Oct 14, 2012 (gmt 0)

Well, not with that many addons. My own most complicated sums seem to come out in RegEx constructors like

expr = new RegExp ("<td>\\[dot" + count + "\\] *(\\[" + langname[count] + "\\])? *(=\w\w)? *","g");

where "count" is what it looks like, an iteration of a "for..." loop. In the code snippet that I coincidentally asked about a few days ago, it doesn't get any fancier than

newstring = '<img src = "http://www.example.com/pictures/smallgifs/dot7' + pagenum + '.gif" width = "1" height = "1" alt = "">';
document.getElementById("clicker").innerHTML = newstring;

where pagenum is a preset integer. Doesn't have to be an integer, though. An earlier variant of the same routine used
(form inconveniently depends on browser) and plugged in the result approximately where I had "pagenum" above. But you see already that you can have more than one +

Note alternation between single and double quotes, since you need to produce output containing literal quotes. The alternative-- which is perfectly legitimate but visually more confusing-- is to escape each literal quotation mark.

If you're using innerHTML, the anchor equivalent would be something like
<span id = "javahere">&nbsp;</span>
Put that in place ahead of time. Its sole function is to create a place for you to pop the result into.

Now do whatever you have to do to get your two "cost" variables, and make sure they're in the correct form-- numerical value in the appropriate range, correct number of decimal places etc-- before you plug them into the code. You want integers, I guess, since your code follows each one with %2e and two digits. They will magically change back into strings if you add them to a string variable.

mystring = '<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_xclick-subscriptions&amp;business=xxxxxxxxxxxx&amp;lc=US&amp;item_name=Auto%20Proxy%20Posting&amp;no_note=1&amp;no_shipping=2&amp;a1=' + cost1 + '%2e00&amp;p1=1&amp;t1=M&amp;src=1&amp;a3=' + cost2 + '%2e11&amp;p3=1&amp;t3=M&amp;currency_code=USD&amp;bn=PP%2dSubscriptionsBF%3abtn_subscrib">';
document.getElementById("javahere").innerHTML = mystring;


<span id = "javahere"><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_xclick-subscriptions&amp;business=xxxxxxxxxxxx&amp;lc=US&amp;item_name=Auto%20Proxy%20Posting&amp;no_note=1&amp;no_shipping=2&amp;a1=cost1%2e00&amp;p1=1&amp;t1=M&amp;src=1&amp;a3=cost2%2e11&amp;p3=1&amp;t3=M&amp;currency_code=USD&amp;bn=PP%2dSubscriptionsBF%3abtn_subscrib"></span>

To do it properly, you should include the anchor text and closing </a> inside the span, and remember to include them in the "mystring" otuput. In fact you can do both together:

<span id = "javahere">anchortext</span>

mystring = document.getElementById("javahere").value;

newstring = '<a href {all the stuff you had before, winding up with} abtn_subscrib">' + mystring + '</a>';

document.getElementById("javahere").innerHTML = newstring;

AND if your <a href> also happened to have an id, you could now use the same function to pull out the anchor text and change it separately. But let's not go overboard.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved