Solved

Javascript querystring

Posted on 2013-06-24
6
320 Views
Last Modified: 2013-06-24
Hi Experts,

I have the code below, that essentially should take the contents of one textbox, reload the page and place the querystring back into the textbox. The only problem I have is it places the text in but it disappears straight away. I tried the second line with a different textbox but got the same issues

function redirec() {
            location.href = "index.html?" + document.getElementById('Text1').value;
            document.getElementById('Text1').value = window.location.search.slice(1);
        }

Open in new window

0
Comment
Question by:takwirirar
  • 3
  • 3
6 Comments
 
LVL 53

Expert Comment

by:COBOLdinosaur
Comment Utility
the population of the textbox has to be done in the new page onload. You have a new page loaded that has no clue what instructions were executed from the previous page. the only reason you see it briefly id that javascript does not way for commands to finish executing before it does the next instruction.



Cd&
0
 
LVL 1

Author Comment

by:takwirirar
Comment Utility
I have this in the second page but the text box is not prepopulating

 <script type="text/javascript">

        function onll() {

           document.getElementById('Text1').value = window.location.search.slice(1);
        }


    </script>
</head>
<body onload="onll">
    <input id="Text1" type="text" />
</body>

Open in new window

0
 
LVL 53

Expert Comment

by:COBOLdinosaur
Comment Utility
From the tiny snippets, it looks like it should work.  The fact that it does not means there is something in the page or on the server side screwing it up.  Post a link and maybe we can get a better idea of why it is not working.

Cd&
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 1

Author Comment

by:takwirirar
Comment Utility
Ok thanks the link is http://apaneapa.com/index1.html
0
 
LVL 53

Accepted Solution

by:
COBOLdinosaur earned 500 total points
Comment Utility
<body onload="onll">

Should be:

<body onload="onll();">

It is only when you fire from inside the script that you leave of the parenthesis.

Cd&
0
 
LVL 1

Author Closing Comment

by:takwirirar
Comment Utility
Fantastic and quick responses.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now