1

I've hit something of a snag, and rather than revert to using a form, I'd like to see if I can make this work. I'm using an onclick event to add a value to a database, part of which is a url. Here's my code;

<a onclick="$(this).load(encodeURI('a_addprice.cfm?productid=#productid#&price=#price#&stockstatus=#stockstatus#&deeplink=#deeplink#&provider=#provider#&supplier_name=#supplier_name#&itemref=#itemref#&storeid=#storeid#'));">Add</a>

(the hashtags are related to my backend language, Coldfusion - for those that are unaware)

In plain HTML, this is how it would look;

<a onclick="$(this).load(encodeURI('a_addprice.cfm?productid=1&price=10.99&stockstatus=In Stock&deeplink=http://www.supplier.com/?product=1&something=2&provider=providername&supplier_name=supplier_name&itemref=ABC1&storeid=123'));">Add</a>

The problem I'm having is with this part (deeplink);

http://www.supplier.com/?product=1&something=2

When the action is performed, it's ignoring everything in the URL past ?product=1. Of course, this makes sense because of the way the URL is structured - if it didn't, it would also be adding '&provider=... etc as part of the deeplink too.

What I'd like to know is whether there is a way I can still use this method, perhaps isolating the deeplink aspect so its included in full.

The page this is included on has around 100 rows like this, so I'm basically trying to avoid having 100 forms, together with all the extra hidden variables each form would need.

1 Answer 1

1

I feel you have placed the encodeUri in the wrong part

$(this).load(
'a_addprice.cfm?productid=#productid#&price=#price#&stockstatus=#stockstatus#&deeplink='+
 encodeURI('#deeplink')+
'#&provider=#provider#&supplier_name=#supplier_name#&itemref=#itemref#&storeid=#storeid#'));

Also I would strongly suggest you change that to something like #URLEncodedFormat(deeplink)#

and have a link like

<a  class="deeplink"
href="a_addprice.cfmproductid=#productid#&price=#price#&stockstatus=#stockstatus#&deeplink= #URLEncodedFormat(deeplink)#&provider=#provider#&supplier_name=#supplier_name#&itemref=#itemref#&storeid=#storeid#">...</a>

and use

$(function() {
  $(".deeplink").on("click",function(e) {
    e.preventDefault();
    $("someResultContainer").load(this.href);
  });
});
Sign up to request clarification or add additional context in comments.

1 Comment

thanks for the reply. I abandoned the use of encodeURI and went with your second suggestion, which worked perfectly - thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.