Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jun 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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!

  • #2
    hgs
    hgs is offline
    New Coder
    Join Date
    Jan 2010
    Location
    Germany
    Posts
    83
    Thanks
    3
    Thanked 5 Times in 5 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •