[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 7042
  • Last Modified:

Use javascript to change input value

How do I use javascript to change
<input type="hidden" name="redirect_url" value="something.html" />
to
<input type="hidden" name="redirect_url" value="something_else.html" />
?

Thanks
0
nericksx
Asked:
nericksx
  • 5
  • 4
1 Solution
 
netsmithcentralCommented:
<script type="text/javascript">
document.getElementsByName("redirect_url")[0].value = "something_else.html";
</script>

But you would be better off using ID'ed elements:

<script type="text/javascript">
document.getElementById("redirect_url").value = "something_else.html";
</script>
<input type="hidden" id="redirect_url" value="something.html" />
0
 
nericksxAuthor Commented:
Bugger.  That didn't seem to work.  Here's what I'm trying to do:

I have a form that uses ../cgi-bin/xmlformmail.cgi and when submitted redirects to ../thanks.html.  Then of couse, the URL that shows on the thanks.html page is: ../cgi-bin/xmlformmail.cgi and I need it to be ../thanks.html because I need to tack some tracking stuff on to it.  I thought that swapping out the redirect URL on the form page would do it, but it doesn't.
0
 
netsmithcentralCommented:
If your using Perl as your CGI source, you need to do the redirect there.  Here' an example of how to do a redirect page in Perl:

#!/usr/bin/perl
print "Status: 302 Moved\nLocation: ../thanks.html\n\n";
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!

 
nericksxAuthor Commented:
Yeah, but it's a global script and I can't change it.  I have to do it from the form or the thanks page.
0
 
netsmithcentralCommented:
Can you post the source of the xmlformmail.cgi?
0
 
nericksxAuthor Commented:
'fraid not.  My company would have a cow. :-S  Sorry to be such a pain.
0
 
netsmithcentralCommented:
Hmm.  Well, unfortunately I think you're going to have to talk to the tech support guys at your company then.  The problem is the xmlformmail.cgi page is not processing the form the way you expect.  Without seeing the source of that page, we cannot help you know why.
0
 
b0lsc0ttCommented:
Do you want to change where the form is submitted?  If not do you want to change what the xmlformmail.cgi page does?  If not then do you want xmlformmail.cgi page to be used but appear to be thanks.html?

Which of the three or please clarify?  You can use javascript to change where the form is submitted.  The script would need to be in the form page.  You can't use script in another page to do this.

If the second you have to make the change in the xmlformmail.cgi page and script.  If you can't change the script then you won't be able to change what happens.  You can't use Javascript to "fake" the URL.  The browser will always show the correct URL (frames can be an exception to that in a way).  Server script can be a way around this but not client side script like Javascript.

Let me know how this helps or if you have a question.

bol
0
 
nericksxAuthor Commented:
I want the xmlformmail.cgi page to be used but appear to be thanks.html.  

A co-worker swears that they did this before by somehow swapping out the value of the hidden redirect_url field.  Somehow this made it so the page still parsed through the CGI correctly but showed the actual native URL on the end (thanks.html).
0
 
netsmithcentralCommented:
You page, xmlformmail.cgi, is responsible for handling the value of redirect_url, NOT the calling page or thanks.html.  Without being able to modify xmlformmail.cgi or more information about how it works, the ONLY thing we can do is write a new page (thanks.html) which does a background post to xmlformmail.cgi and then does the redirect itself.

EXAMPLE (Note: You must use the "GET" action with the form for this page to work):
<html>
<head>
<title>XML Form Mail Background Post</title>
<script type="text/javascript">
<!--
var error;

window.onload = function(){
    var req = null;
    if(window.XMLHttpRequest) req = new XMLHttpRequest();
    else if(window.ActiveXObject){
        try {
            req = new ActiveXObject("Msxml2.XMLHTTPREQUEST");
        catch(e){
             try {
                req = new ActiveXObject("Microsoft.XMLHTTTPREQUEST");
             } catch(e) {}
         }
     }

     if(req==null){
         error = "Document failed to post your form data.  Your browser\n" +
                     "does not support AJAX!";
       
         return;
    }

     var data = document.location.href.split('?')[1];
     
     req.open("POST", "xmlformmail.cgi", true);
     req.send(data);

     if(req.status!=200) error = "Document failed to post your form data.  There\n" +
                                                "was an internal server error.";
}
//-->
</script>
</head>
<body>
<p><script>document.write(error);</script></p>
Thanks!
</body>
</html>
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now