Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-01-2010, 12:11 AM   PM User | #1
davcom1
New to the CF scene

 
Join Date: Jun 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
davcom1 is an unknown quantity at this point
Question Adding dynamic URL links to a function - Help!

First off, I apologise for being stupid and I previously posted this in the DOM section but had no luck with any replies.

My skills with JavaScript are limited to adapting existing code only

I have a calculator which generates values within a form, using "onChange" calls to a function.

I want to provide links to matching products depending on the calculated result and have added If..Else..If.. to the function to produce a URL where the result is matched within number ranges.

I cannot get this result to be a clickable link - I'm sure it is a simple thing to do but I've tried a few things and am not even close!

Page is here:

http://www.homesupply.co.uk/radcalc99.php

I've added the following code:

Code:
if (answer==undefined)
		{
			lnk="products.php?cat=581&opt=,Various";
		}
		else if (answer<500)
		{
			lnk="products.php?cat=581&opt=,Less than 500";
		}
		else if (answer>499 && answer<750)
		{
			lnk="products.php?cat=581&opt=,500-749";
		}
		else if (answer>749 && answer<1000)
		{
			lnk="products.php?cat=581&opt=,750-999";
		}
		else if (answer>999 && answer<1401)
		{
			lnk="products.php?cat=581&opt=,1000-1400";
		}else if (answer>1400)
		{
			lnk="products.php?cat=581&opt=,Over 1400";
		}
		document.theForm.dlnk.value =(lnk);
	}
And also:

Code:
<input type="button" name="dlnk" size="20" value="" class="total" />
Any assistance would be very welcome!
davcom1 is offline   Reply With Quote
Old 07-04-2010, 09:54 AM   PM User | #2
hgs
New Coder

 
Join Date: Jan 2010
Location: Germany
Posts: 52
Thanks: 1
Thanked 2 Times in 2 Posts
hgs is on a distinguished road
in your page define something like this:
Code:
 <a href="" id="ahref" >your Product</a>
In your posted code exchange

Code:
document.theForm.dlnk.value =(lnk);
with
Code:
 document.getElementById('ahref').href=lnk;

Hope this works for you.
Regards
Heinz
hgs is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:21 AM.


Advertisement
Log in to turn off these ads.