Home › Forums › JavaScript › A Catched value of a input-field by JS, is lost arriving at the destinationpage
- This topic is empty.
-
AuthorPosts
-
December 17, 2014 at 3:11 am #191035First ThingsParticipant
Hello,
I build a website, using a bought template.
In the template there is a not working search-form (only the design code is in the template).
So i had to let it work by adding some fundamental code:
1) Catching the filled in search-term with JS
2) And adding the action code to the form (tell the form the destination page) also done with JS.Now my search-form is working in safari, but not in Chrome or Firefox. Seems to be the added search-term is lost arriving on the destination page…
My template is using a lot of JS… But i’m not a ninja in JS.
I know there are ways to check everything that happens when a page is load or a button is clicked… but i nut used to work with those things…
I tried, but i cannot find the problem/event that is responsable for loosing my catched search-term.
Hope that you could help to find a solution…
Any tips, links, info is welcome!Here is the website:
http://www.woodtex.be (to activate the search-form, click the search-icon on top of the page)December 17, 2014 at 1:03 pm #191093shaneismeParticipantCatching – do you mean caching?
If so, how are you storing the data on the search field in between postbacks?
December 19, 2014 at 3:52 am #191232itsLeonParticipant@First Things,
By the looks of it the form is submitted before the js function has changed its action and retrieved its value from the input.
Also because you support searching directly in the url there is no need for a form.
You only have to change the url (/search/node/betonplex).$(document).ready(function(){
`$(“#search”).keypress(function(event){
if ( event.which == 13 ) {
event.preventDefault();//get value var value = $(this).val(); //simple check if(value == "" || value == " " || value == $(this).attr("placeholder")){ //nothing has changed }else{ //something has changed //change to url, /search/node/+value; //window.location.href="/search/node/"+value; } }
});
`});
for some strange reason jsfiddle won’t save my code
December 22, 2014 at 9:44 am #191437First ThingsParticipant@shaneisme —> Thank you for the reply, i think i should have said caching… You can see the code between on line 97 and 110.
@itsLeon —> Also thanks for the respond and the code. I did try to implement it but it did not work. After i hit enter, it stays then at the same page. I tried to change some code to make it work, but no solution was find…Thanks anyway for the responds, i will look further..
K.
December 23, 2014 at 1:42 am #191473itsLeonParticipantHold on. You can see the code running here: http://codepen.io/anon/pen/xbEwxL
If it still won’t work contact me again and we will look for a solution
February 6, 2015 at 8:14 am #195220First ThingsParticipantVery much thanks for the code on codepen. I did try to work with it in the beginning of januari. Then I was very bussy with other projects. Today i tried again to integrate your code in my website, but no succes…
For me it was/is important that the CSS/HTML/JS code from my start-template is not changed… so the form should stay…
I also spoke with someone a couple weeks ago about this issue… He said that Firefox is very strict in URL creation by forms and JS… Thats why the code that is used now, is working perfect in Safari and not in firefox…
So, thank you again for the support itsLeon!! It maybe did not help me 100%, but i learned a liitle bit more…
-
AuthorPosts
- The forum ‘JavaScript’ is closed to new topics and replies.