Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Javascript querystring

Posted on 2013-06-24
6
321 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

 
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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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
Google Maps API and PHP 25 49
Binding a Grid in Javascript 5 43
How  can  I extract  Id  from a  URL  using  Javascript? 12 29
HTML Anchor Link Problem 3 35
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

860 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