I have two html pages. from one html if I am clicking the id which i have made as a link I want the data associated with that to be populated into the other html page.Its like the id of an employee is being cliked and all te values associate dwith it like his name, address and gender should get populated in the text fields in the previous html table. Currently I am not using any DB. I have entered everything manually through html. I want to use only Java script.
If I understand your question: Yes, it can be done. (I don't know why you would want to do this without a database, but it is possible.) When you're making the links on your first page, make sure they contain the information you want in query string format like this:
Bob Smith
Then on your second page, you can use JavaScript to parse window.location.search which is the query string that you passed from your first page. You can do this in many ways. Here is an example function that will let you extract variables from the query string. You could use it like this on the second page:
<script type="text/javascript">
var firstName = getParameterByName('firstName');
var lastName = getParameterByName('lastName');
var gender = getParameterByName('gender');
// now do something with those variables.
</script>
Related
I have a talend job that goes like the above one and i am using a select statement to access the data from oracle
select id,name,details from employee ;
and send the results via email.However for a particular column details it has 10 different lines and that are dynamic and has various other unwanted/irrelevant information and i would like to precisely filter few lines and print them to the mail using tjava component.
How can i do that?
for eg:details column has values like:
"hi i am john
i work at abc
i go to oxford
i reside at 1st street
goodbye"
so the lines are totally random,i would want to match based on a specific keyword lets say "reside at" alone and filter that for different records and capture that in that output?
In order to do this you need to create a custom SQL query in the tDBinput.
"select id,name,details from employee
where details like '%reside at%'"
(Where the % are any text check the SQL "LIKE" function for more details)
With this you will filter the row you want.
If you need more filter you can modify you SQL query like you want.
I have a website where I have to save search when I press the save search I have the whole query string like this ?s=&variable1=&variable2= ... and over 100 other variables I want to take this whole query string and save into a single variable to save it inside database column url
var query=form.serialize
how to save whole query string into a single variable to pass it through ajax to php?
The url is relative sometimes fields are about properties sometimes about cars sometimes about mobile phones so can't call every single one.
You can save save URL parameters using like this:
let query = window.location.search;
Is that what you are looking for?
On websites such as eBay, upon returning to a search page, the search options are all filled in. I'd like to do the same with my website, where currently, returning to the search page returns the correct search results but the search form is empty.
The two approaches I've seen to this so far:
Have the form written in HTML, use JS to parse query string and set form values.
How can I pre-populate html form input fields from url parameters?
Generate the form in JS with any values in the query string, this will make a blank form if there's no query string given.
Query String for pre-filling html form field
Both these solutions seem hack-y. I'd imagine that this is a common task, is there a standard or clean method to do this in one or two lines?
There is obviously something that serializes the fields from a form to a query string, there should be a way to use that in reverse to take the query string and fill in the form fields, without having to "roll your own" loop in JS.
I'd suggest saving the information in a session/cookie and pulling from that to populate the form. That's how it's done on eBay.
Just use GET parameters.
http://sample.com/?search=pen&color=blue
Now while building your form elements, just do something like:
$search = isset($_GET['search']) ? $_GET['search'] : '';
$color = isset($_GET['color']) ? $_GET['color'] : '';
echo "<input type='text' value='{$search}' placeholder='Search' />";
echo "<input type='text' value='{$color}' placeholder='Color' />";
I want to create a web page with selections then when a user inputs their selections I would like an output of a code (or even better a unique url) which can be copy-pasted to forums, e-mailed etc... Allowing their friends to click the link and retrieve the input selections associated with that link.
A code would be fine where a link + a code that is copy/pasted into a text box then generated the shared entries.
So for instance I have several drop down boxes:
A drop down with 50 states, a drop down with gender, a drop down with
ages 1-100, a drop down with number of kids.
An end-user comes and selects whatever choices they want and the page
produces the link or code allowing future end-users to either click
the link (preferable) or paste the code into a text box which then
selects all the appropriate selections wishing to be shared. This
allows the second user to view exactly what the first user wanted to
share with a simple short link/code.
I am stuck and I know I don't have to create a unique webpage for each possibility but I'm not sure how to approach.
How do I save the first users selections, then generate a unique code/link, and finally display the first users selections for a subsequent user?
What you probably want are url parameters..
Here's a function that uses regex to grab a param from the url
function gup( name ){
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp( regexS );
var results = regex.exec( window.location.href );
if( results == null ) return "";
else return results[1];
}
I wouldn't sweat what's going on in there.. but to use it you'ld have a url (mysite.com/coolPage) if they go there with a parameter (mysite.com/coolPage?whosCool=ImCool)
you can, in your javascript call gup("whosCool") and it'll return "ImCool"
in your example, you'ld have mySite.com?state=oklahoma&gender=male
in your javascript you can, on load:
document.getElementById('state').value = gup('state');
document.getElementById('gender').value = gup('gender');
to build the url, when they make all of their selections you'll build the url with the parameters.
var url = "mycoolSite.com/mypage?";
url += "state=" + document.getElementById('state').value;
url += "gender=" + document.getElementById('gender').value;
document.getElementById('outputURL').innerHTML = "<a href='"+url+"'>Your url</a>";
That's the pieces, you'll have to build it all together though
I can think of two ways to do this:
Unique database id which stores all the information for that user and is generated when they generate the link.
A much longer url with all the options stored as parameters on the end.
Database solution
When the user clicks to generate the link I'd take all the information gathered from the page, and push it through in a form for processing. I'd then store all the information in a database with a unique id and pass that id back to the user, storing it as a parameter in the url that is in the generated link.
When the user clicks the link the first thing you could do on page load is to query the id parameter and display all the database fields that have been previously stored.
Depending on whether you have any PHP knowledge, you might find these links useful:
https://gist.github.com/webaware/4048580
http://www.dynamicdrive.com/forums/showthread.php?45895-How-to-populate-php-html-form-with-MySQL-data
URL parameters solution
I'd again gather all the information from the page and push it through in a form before building a link with the parameters listed out. So www.tester.com?gender=female etc.
When the user clicks the link the first thing you could do on page load is to pull the parameters from the link and display them against the appropriate inputs.
This might get you off the ground with the basics for doing this with javascript.
Pre-fill form field via URL in html
Get the info from the form: How to save data from a form with HTML5 Local Storage?
This one will be particularly helpful to you: How can I pre-populate html form input fields from url parameters?
This second option is definitely messier and I'd probably go with the first option myself.
Hopefully they both make sense - any questions then just ask!
I'm developing a project with jsp.
There are two text boxes on the page. If I select first text box i get the list of countries fetching from MySQL database, I have done it with jQuery. now the problem is:
with out any events(especially buttons) automatically in the 2nd TEXT BOX the states/cities should be populated.
Does anybody have any idea? I used most of the JavaScript events such as onselect, onclick, etc. but no use.
And I'm not supposed to use a dropdown list.
Are you using .ajax or .get to get the list of countries from the database?
If you are, try using .getJSON instead. You can provide effectively an array of responses, therefore meaning your first response from the AJAX script data.countries and the second element in the json array is data.states.
jQuery
$("#text-box").click(function(){
$.getJSON('ajax/get-locations.jsp', function(data) {
$('#div-countries').html(data.countries);
$('#div-states').html(data.states);
});
});
JSP
// Query to get countries
// Build html for countries list (stored in $countriesHTML)
// Query to get states
// Build html for states list (stored in $statesHTML)
// Put html in json array and echo / print / output the json as the result of your script (in the below format, replace $countriesHTML and $statesHTML with your own variables for the HTML).
echo '{ "countries": $countriesHTML, "states": $statesHTML }'
I hope this makes sense, I've not done JSP in ages which is why I've not attempted to code it, but the above seudo-code should be the theory applicable to any scripting language.