CodeCharge Studio
search Register Login  

Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> General/Other

 Autocomplete with URL param

Print topic Send  topic

Author Message
laneoc

Posts: 154
Posted: 08/09/2017, 8:41 AM

I'd like my JQuery autocomplete to use two parameters in the search: the "term" plus a URL parameter from the source page ("cnum").

Any tips, leads, suggestions??


_________________
Lane
View profile  Send private message
MichaelMcDonald

Posts: 640
Posted: 08/13/2017, 5:51 AM

$.urlParam = function(name){
var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href);
if (results==null){
return null;
}
else{
return results[1] || 0;
}
}
cnum = ($.urlParam('cnum'));
_________________
Central Coast, NSW, Australia.

View profile  Send private message
laneoc

Posts: 154
Posted: 08/13/2017, 12:50 PM

Thanks for the response Michael McDonald.

Where would this code belong? Would it overlay the Ajax autocomplete javascript generated by CCS? Supplement it?

_________________
Lane
View profile  Send private message
MichaelMcDonald

Posts: 640
Posted: 08/15/2017, 5:33 AM

Sorry I automatically went down the path of a pure jquery solution. If this doesn't work for you with CCS autocomplete,etc .. I can build it into a json_encode that passes your variable to a php page using ajax POST which passes it back as a json_encode array and produces the same end result.

What I can say is I do know CCS can grab the variable if it is placed into a field that can be used in a dlookup and the result placed into another field.

But if you wouldn't mind checking to see if this helps anyway first, it's not tested ,but will be close. If your text field doesn't have an id make sure it does by giving it id="textfield_someID" next to name="whatever"

Then using the jquery focus out event to demonstrate what happens when leaving a text box - it will get that url param and fill any textbox (can be the one you want autocompleted with cnum). You could however bind using any jquery event at all - an onchange for a select, or a button onclick

<script>

$("#textfield_someID").focusout(function () {

$.urlParam = function(name){
var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href);
if (results==null){
return null;
}
else{
return results[1] || 0;
}
}
cnum = ($.urlParam('cnum'));

$('#textfield_someotherid').val(cnum);

});

</script>
_________________
Central Coast, NSW, Australia.

View profile  Send private message
laneoc

Posts: 154
Posted: 08/15/2017, 1:17 PM

After spending a bunch of time trying to use jQuery Autocomplete (not the built-in CCS autocomplete), I'm giving up on troubleshooting CSS issues, etc. and I'm headed another direction.

Instead of trying to form a call to the php search code with an additional parameter, I'm using CCS' autocomplete after storing the needed parameter in session. Then I modified the search code to use the session variable as a parameter.

I wish I was better at using jQuery and Ajax.
_________________
Lane
View profile  Send private message
laneoc

Posts: 154
Posted: 09/09/2017, 8:17 AM

I'm looking for recommendations on how to get smarter in jquery or ajax beyond what CCS code-gens for me.

I have another autocomplete scenario where I need to have the lookup use the {term} plus another variable. But this time the variable is one of the other input fields, so I can't use the session variable workaround. There will be more applications, I'm sure.
_________________
Lane
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

PHP Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.