I am trying to add an html input box to allow users to set a value which adjusts the result returned from a sql request. My request currently contains a parameters to which a variable is supplied and sent as a request.
I am new to jquery and uncertain as to how to fetch the user inputted value as previously done with the simple getElementById in JavaScript.
My jquery is:
var schema = 'sewer_pipelines';
$.getJSON("sql_query.php", // The server URL
{ parameter: schema },
saveToArray
);
Is there a method which will allow for user input in this approach?
You have to use a selector like this :
var schema = $('#sewer_piplines').val();
More on jquery selectors : https://api.jquery.com/category/selectors/
Thanks for the help, problem is now sorted.
Working code is:
var schema = $('#attribute_parameter').val();
$.getJSON("sql_query.php", // The server URL
{ parameter: schema },
saveToArray
);
var value= $('#inputid').val();
Related
I have 5 textboxes(cfinput) on my form to enter organisation code. What I want to do is, As the user types the Org code, there should be an onkeyup function that will validate the value with all the values in database and if its invalid it should show "Invalid Code."
I have got all the Org codes in an array called OrgIndexArray. I am not getting, how would I do this for all the 5 textboxes (some sort of cfloop?)
<cfquery name="getOrgCodes" datasource="#sqlDS#">
select distinct OrgCode From #SAUserIndex#
</cfquery>
<cfset IndexCodesList = ValueList(getOrgCodes.OrgCode)>
<cfset IndexCodesArray = #ListToArray(IndexCodesList)#>
<script>
var IndexArray=<cfoutput>#SerializeJSON(getOrgCodes,true)# </cfoutput>
$(document).ready(fucntion() {
$('.IndexCodes').on('keyup',function(){
if(!!~jQuery.inArray($this.val(),IndexArray)) {
document.getElementById("message").innerHTML="Invalid Index";
}
});
});
</script>
The issue at the moment is that all your "validation" data is only available serverside. Ideally you want to use javascript for the validation on the form fields as the user types. This way you can do the validation client side without having to make additional calls to the server.
There are few ways to achieve what you want to do:
One (possibly a bit hacky) way to do this is to use Coldfusion to populate a javascript array in your page:
<script>
var myArray = <cfoutput>#serializeJson(OrgIndexArray)#</cfoutput>;
//use javascript to validate the input by checking the cfinput value with the array.
//assuming you have jquery:
$(document).ready(function(){
$('.classOfYourInputHere').on('keyup',function(){
if ($.inArray( $this.val(), arr ))
{
//do something
}
});
});
</script>
Alternatively you can create an API of sorts, that will allow you to do an ajax request to a coldfusion .cfc to retrieve the array data in javascript and then you would proceed similar to the above.
Please note that this is not tested in anyway, but it hopefully should help you in the right direction.
I have this jQuery code that gets data from my form. I used a console statement to see the value. However I want to pass the data to my Node application so that I can insert into a database.
$(function() {
$('#kiosk_signin').submit(function() {
var data = $('#kiosk_signin :input').serializeArray();
console.log(data[0]);
});
});
Please let me know what I need to do.
Assuming you are using express, posting this to your route.., and inserting into the DB..
You would do something like this in your routes..
router.post('/whereever', function(req,res,next(){
///assuming kiosk_signin is the name of an input field
///and the action is ='/whereever' method='post'
var data = req.body.kiosk_signin
console.log('if you want to log it', data)
db.insert({propert: data}).then(function(){
res.redirect('/home')
})
})
I don't use JQuery for submitting forms if I have a full-stack app, just because I intend on sending it directly to the server. Hopefully that helps..
I have a multi page form.
Page One has a few fields that get passed into the second form, via GET method, and it auto fills the first four fields of the second part of the form.
Page two has a few more questions, and when you submit it, it submits into our CRM(vanillaSoft), and leads to a thank you page.
My current issue:
I want to be able to take an affiliate link, such as:
http://something.com/step-one.html?AFFILIATE_ID=#affid#&SUB_ID=#s1#
I need to dynamically populate the AFFILIATE_ID parameter with a unique transaction ID, and the SUB_ID with a unique ID as well.
I currently have two fields on my first page with hidden fields, ex:
<input type="hidden" name="SUB_ID">
<input type="hidden" name="AFFILIATE_ID">
But that isn't working. I need this date to be sent into the CRM I use.
Any advice?
Thanks!!!
Your current setup will work if you set your form submit method to GET. You probably have it set to POST.
Setting your form method to GET will put those hidden fields in the URL, like you are expecting.
On the last form, set that one to POST (to POST to the server).
You can grab the Query string with JavaScript, like this:
var getParamValue = (function() {
var params;
var resetParams = function() {
var query = window.location.search;
var regex = /[?&;](.+?)=([^&;]+)/g;
var match;
params = {};
if (query) {
while (match = regex.exec(query)) {
params[match[1]] = decodeURIComponent(match[2]);
}
}
};
window.addEventListener
&& window.addEventListener('popstate', resetParams);
resetParams();
return function(param) {
return params.hasOwnProperty(param) ? params[param] : null;
}
})();
How can I get query string values in JavaScript?
You could also send both POST and GET methods. But POST can be done only on server side, where JavaScript is Client-side scripting language.
<form method="POST" action="form.php?a=1&b=2&c=3">
PHP -> Send both POST and GET in a form
How to read the post request parameters using javascript
I am trying to refresh the page while pass an array from an onclick button.
Since I am using yii, posting isn't an option, and setting a session variable wasn't working. Any ideas would help. Thank you
<a style="width:100%;" onclick="my_picks_reset()" id="my_picks_reset">Reset</a>
<script>
$(function() {
/*set var picks = array of TBA and reset th my_picks div*/
$("#my_picks_reset").click(function() {
var my_picks = ['TBA','TBA','TBA','TBA','TBA','TBA','TBA','TBA'];
var url = document.URL;
$(location).attr('href',url,'my_picks',my_picks);
})
})
</script>
It seems from your comments that you're expecting POST request. Changing location of the page will give you GET request. So you have two options here:
1) Continue using location and read the the values from $_GET variable.
If you decide to use this option your need loop through my_picks array and construct the query string that would look like that:
?my_picks[]=arrayValue1&my_picks[]=arrayValue2... and do location.assign(currentLocation + composedQueryString)
2) The second better solution is to use $.ajax() to send values with post method.
I am hoping for your help on this one.
I am using Fineuploader and I need to get and send input field value (that will be file group title).
For that I am using path to server side script (I didn't code it thats why I have to do it on my side, somehow):
endpoint: '/Services/hndFileUploader.ashx?case=deals&dealfiletitle=' + $("input").val()
Problem is that DOM with Fineuploader is already loaded and value of input is of course empty.
How can I get dynamic value to send with that query?
Thank you.
You do this using the setParams option for fineuploader. Docs are here, but basically it could be something like:
$('#fineUploaderElementId').fineUploader({
request: {
endpoint: '/Services/hndFileUploader.ashx'
}
}).on('submit', function(event, id, filename) {
$(this).fineUploader('setParams', {'case': 'deals', 'dealfiletitle': $(input).val(); });
});