Hi
The link below produces a page refresh. Is there a way to add a parameter to it without breaking the javascript, and if so, how would it be retrieved?
<a href="javascript:this.location.reload(); ">refresh</a>
Thanks!
This is a discussion on Javascript Question in the Design and Development forum
Hi
The link below produces a page refresh. Is there a way to add a parameter to it without breaking the javascript, and if so, ...
Hi
The link below produces a page refresh. Is there a way to add a parameter to it without breaking the javascript, and if so, how would it be retrieved?
<a href="javascript:this.location.reload(); ">refresh</a>
Thanks!
You could use window.location.replace(someURL);, where in someURL you could put window.location.href plus any GET parameters you want to add.
Regards,
Wim Heemskerk
---
Visit MeCCG.net - Cardgaming in J.R.R. Tolkien's Middle-earth
And Gwaihir.net - The Middle-earth CCG store
Using <a href="javascript:window.location.replace (new_record.php?param=test);">refresh</a> causes the link to no longer function (nothing happens when clicked). Using <a href="javascript:this.location.reload(); ">refresh</a> will produce a link that reloads the current page, but more is needed.
Here is what I'm trying to accomplish:
- Provide a form to the user to begin entering information for adding any number of new records (the form allows the user to enter the number of new records to insert).
- After submitting, pre-insert the values entered into the first form on a new form, and duplicate it x number of times, where x is the number of new records requested. (This allows the user to enter any info common to all of the new records only once, then fill in the rest of the info for each record where it differs.)
- There are certain fields that are optional. By default these fields do not appear, only a link to add them. If the user clicks the link at this point, I need the page to refresh to reload the current page and all of the info it contains, but with a parameter I can retrive to tell me to include the optional fields now.
If a link could be created that reloads the page AND sends a parameter (something like action=add_optional_fields), this would work.
Is this on the right track, or is there a better way entirely to accomplish this perhaps?
Thanks!
I meant someUrl as a variable, as I assumed you wanted to set the url dynamically. To put in a literal value like that, simply add quotes around it. Oh, and loose the space after .replace. I doubt all browsers support it.
<a href="javascript:window.location.replace ('new_record.php?param=test');">refresh</a>
BTW: something does happen when you try yours: you get a javascript error. I can recommend using Firefox + Firebug to help you make sense of those.
That's regarding the original question. As for the bigger picture: this won't work well. If you refresh the page like that, the user will loose all the info he has entered but not yet submitted. It would be much simpler to put all the fields in all the time, but hide those optional ones (display:none in your css). Your javascript link(s) would then not refresh the page, but show the hidden fields.
Regards,
Wim Heemskerk
---
Visit MeCCG.net - Cardgaming in J.R.R. Tolkien's Middle-earth
And Gwaihir.net - The Middle-earth CCG store
The quotes were needed around the parameter, now the link functions. However, that javascript (javascript:window.location.replace) does not produce a page refresh (which I see below you do not think is needed). I would not need any javascript at all to send a parameter with a link and retrieve it, it was the page refresh via a link AND a new parameter I was after.
Hmmm, I do not get a javascript error in the error console of Firefox 3.6.8., just a page refresh.BTW: something does happen when you try yours: you get a javascript error. I can recommend using Firefox + Firebug to help you make sense of those.
I'm using $_SESSION variables to store everything and that part works fine. I'm thinking I should probably be able to also use $SESSION variables to solve my issue here...I'm just looking to keep it as simple as possible ("...but no simpler..." as Einstein said!)That's regarding the original question. As for the bigger picture: this won't work well. If you refresh the page like that, the user will loose all the info he has entered but not yet submitted.
Yes, hiding them with css may be a good solution. I'll try.It would be much simpler to put all the fields in all the time, but hide those optional ones (display:none in your css). Your javascript link(s) would then not refresh the page, but show the hidden fields.
I'm still curious in general if it's possible to have a link that refreshes a page AND sends a new parameter. The method (javascript, php $_SESSION variables, etc.) does not matter.
Thanks for all of your suggestions.
In what sense? What exactly does that mean to you?
To me, to refresh a page, is to reload it, exactly the way it was initially loaded (same URL, same GET or POST, all the same parameters). That's also how the JavaScript function is named: reload().
So, when you said you want to refresh a page AND send a new parameter, to me that meant you want to load the same page again, with one more parameter added to the URL.
Well, I must admit that I'm at 3.6.4, but nevertheless, as first you confirmed it didn't refresh without the quotes, I think you're confusing some things.Hmmm, I do not get a javascript error in the error console of Firefox 3.6.8., just a page refresh.
That's server side and therefore doesn't include what wasn't submitted to the server yet.I'm using $_SESSION variables to store everything and that part works fine.
Anyway, go for the hiding and showing. Much more elegant.
Regards,
Wim Heemskerk
---
Visit MeCCG.net - Cardgaming in J.R.R. Tolkien's Middle-earth
And Gwaihir.net - The Middle-earth CCG store
In this case, the same POST, because the page on which the reload button would appear is a form, that itself came from a form.
Yes, or sent via POST maybe with a hidden field.
Without any parameters <a href="javascript:this.location.reload(); ">refresh</a> will reload the page, which seems to get me 1/2 the way there. I asked how to send a parameter with the link. Confusing things? No doubt...
Yes, but it's only the info that has been submitted to the server (on the initial form) that needs to be stored.
Elegant yes, but to further complexify things (that's not a word!) the css needs a selector for each item to show/hide. The form allows the user to add a variable number of fields (task fields, in this case) to each record and on each of those task fields to choose whether or not to include dimensions (Length, Width, Height), all in the context of a form that enters a variable number of records. If it were working I'd be bragging...
It's difficult to know how to define the css selectors before the record has been inserted.
To complicate things is the word, I believe. That should not complicate your CSS though. I'd use just one class on all the hideable fields, say "hideable". It changes your JavaScript a bit: that shouldn't unhide all the hidden parts at once, but only those in the part where the button itself is placed. Personally, I'd bring in a library like jQuery or Prototype, because they make it simple to find such elements.
As for the initial line of thinking: indeed, replace() won't help you, as it does a GET, not a POST. You could have your javascript submit the form, but you'd of course have to tell that apart from the "I'm done" submit action. If you're still pondering this line, google a bit for a form with two submit buttons.
Best of success with it! (I'll leave it at this.)
Regards,
Wim Heemskerk
---
Visit MeCCG.net - Cardgaming in J.R.R. Tolkien's Middle-earth
And Gwaihir.net - The Middle-earth CCG store
Copyright © 2011 JaguarPC.com
Bookmarks