Solved

Javascript querystring

Posted on 2013-06-24
6
322 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
ID: 39271543
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
ID: 39271624
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
ID: 39271672
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

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

Accepted Solution

by:
COBOLdinosaur earned 500 total points
ID: 39271744
<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
ID: 39271770
Fantastic and quick responses.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Can't get page to reload 9 18
Worldmap 1 28
Table style position to the left 8 24
Prevent certain words from being typed in a form 6 24
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

679 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