Solved

Javascript querystring

Posted on 2013-06-24
6
323 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
[X]
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
  • 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
Independent Software Vendors: 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

Industry Leaders: 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!

Question has a verified solution.

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

Suggested Solutions

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
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…

732 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