Set value of HTML textbox before redirect

I have an HTML page with HTML input textboxes(for example one of them has the name attribute as email). The HTML page uses a form tag with the method set to post and action set to redirect to another url. I am passing values(name,address,email etc) to this HTML page as a query string. I have a javascript function which reads the values passed. I would like to set the value of the HTML textbox before I redirect the HTML page to the url.

Any ideas on how I can achieve this ?
Thanks,
Aditya
LVL 1
pmac38CDSAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

chaitu chaituCommented:
document.getElementById("email").value=email;
or
document.forms[0].email.value=email;

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
pmac38CDSAuthor Commented:
I am able to read the values from the query string fine. However I am unable to set the value of the HTML textbox. When I try to debug the said statement it appears that the html textbox is null.

Aditya
Amazon Web Services

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

chaitu chaituCommented:
can you paste your html text box?check the id and name of the textbox
pmac38CDSAuthor Commented:
<input type="text" value="" name="email">
Pratima PharandeCommented:

try by giving ID
<input type="text" value="" name="email" id="email">

then

document.getElementById("email").value=email;
pmac38CDSAuthor Commented:
Below is the javascript code I am using
<script language="javascript" type="text/javascript">
    window.setTimeout("pushSubmit()", 1);
    function pushSubmit() {
        var query = window.location.search.substring(1);
        var Whole_Name = getQueryVariable('Whole_Name');
        var cds_name = document.getElementById('cds_name');
        if (cds_name) {
            cds_name.value = Whole_Name;
        }
        document.getElementById('PrePopGateway').submit();
    }
    function getQueryVariable(variable) {
            var query = window.location.search.substring(1);
            var vars = query.split("&");
            for (var i=0;i<vars.length;i++)
            {
                 var pair = vars[i].split("=");
                    if (pair[0] == variable)
                    {
                        return pair[1];
                    }
            } 
  
    }
</script>

and this is the html textbox 
<input type="text" value="" id = "cds_email" name="cds_email">

When I add a breakpoint to the following line of code and step into it, it returns a null value
var cds_name = document.getElementById('cds_name');

Thanks,
Aditya

Open in new window

chaitu chaituCommented:
put  textbox before script is getting executed..I think you are putting textbox after executing the textbox
<input type="text" value="" id = "cds_email" name="cds_email">


<script language="javascript" type="text/javascript">
    window.setTimeout("pushSubmit()", 1);
    function pushSubmit() {
        var query = window.location.search.substring(1);
        var Whole_Name = getQueryVariable('Whole_Name');
        var cds_name = document.getElementById('cds_name');
        if (cds_name) {
            cds_name.value = Whole_Name;
        }
        document.getElementById('PrePopGateway').submit();
    }
    function getQueryVariable(variable) {
            var query = window.location.search.substring(1);
            var vars = query.split("&");
            for (var i=0;i<vars.length;i++)
            {
                 var pair = vars[i].split("=");
                    if (pair[0] == variable)
                    {
                        return pair[1];
                    }
            } 
  
    }
</script>

Open in new window

chaitu chaituCommented:
I think you are putting textbox after executing the whole script
chaitu chaituCommented:
 <input type="text" value="" id = "cds_email" name="cds_email">


   // window.setTimeout("pushSubmit()", 1);
    function pushSubmit() {
        var cds_name = document.getElementById('cds_email');
            alert(cds_name)
chaitu chaituCommented:
    window.setTimeout("pushSubmit()", 1);
    function pushSubmit() {
      //  var query = window.location.search.substring(1);
      //  var Whole_Name = getQueryVariable('Whole_Name');
        var cds_name = document.getElementById('cds_name');
		alert(cds_name)
      
       // document.getElementById('PrePopGateway').submit();
    }
    function getQueryVariable(variable) {
            var query = window.location.search.substring(1);
            var vars = query.split("&");
            for (var i=0;i<vars.length;i++)
            {
                 var pair = vars[i].split("=");
                    if (pair[0] == variable)
                    {
                        return pair[1];
                    }
            } 
  
    }
</script>

<input type="text" value="" id = "cds_name" name="cds_name">

Open in new window

pmac38CDSAuthor Commented:
I tried moving the textbox declaration before the javascript methods but it gave me an error.
chaitu chaituCommented:
    window.setTimeout("pushSubmit()", 1);
    function pushSubmit() {
        var query = window.location.search.substring(1);
        var Whole_Name = getQueryVariable('Whole_Name');
        var cds_email = document.getElementById('cds_email');
        if (cds_email) {
            cds_email.value = Whole_Name;
        }
        document.getElementById('PrePopGateway').submit();
    }
    function getQueryVariable(variable) {
            var query = window.location.search.substring(1);
            var vars = query.split("&");
            for (var i=0;i<vars.length;i++)
            {
                 var pair = vars[i].split("=");
                    if (pair[0] == variable)
                    {
                        return pair[1];
                    }
            } 
  
    }
</script>

<input type="text" value="" id = "cds_email" name="cds_email">

Open in new window

pmac38CDSAuthor Commented:
Can you please elaborate the difference between the two? Where do you want me to place the textbox ?
chaitu chaituCommented:
tell me first are your getting

 var cds_email = document.getElementById('cds_email');

are you able to putting the value for this textbox?
chaitu chaituCommented:
problem is you are retreving the wrong textbox id in the pushSubmit method.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.