pmac38CDS
asked on
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
Any ideas on how I can achieve this ?
Thanks,
Aditya
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
Aditya
can you paste your html text box?check the id and name of the textbox
ASKER
<input type="text" value="" name="email">
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
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>
I think you are putting textbox after executing the whole script
<input type="text" value="" id = "cds_email" name="cds_email">
// window.setTimeout("pushSub mit()", 1);
function pushSubmit() {
var cds_name = document.getElementById('c ds_email') ;
alert(cds_name)
// window.setTimeout("pushSub
function pushSubmit() {
var cds_name = document.getElementById('c
alert(cds_name)
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">
ASKER
I tried moving the textbox declaration before the javascript methods but it gave me an error.
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">
ASKER
Can you please elaborate the difference between the two? Where do you want me to place the textbox ?
tell me first are your getting
var cds_email = document.getElementById('c ds_email') ;
are you able to putting the value for this textbox?
var cds_email = document.getElementById('c
are you able to putting the value for this textbox?
problem is you are retreving the wrong textbox id in the pushSubmit method.
http://www.bloggingdeveloper.com/post/JavaScript-QueryString-ParseGet-QueryString-with-Client-Side-JavaScript.aspx
http://nishantrana.wordpress.com/2009/06/16/reading-querystring-using-javascript/
http://javascript.about.com/library/blqs1.htm