Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Jul 2011
    Location
    USA
    Posts
    39
    Thanks
    0
    Thanked 1 Time in 1 Post

    Add Values to URL

    Hi guys! I'm pretty much lost when it comes to javascript and I'm hoping somebody can help me. What I have is a form that when the "Do URL" button is clicked, it drops the url into the text field. But now I want to be able to add values to the url when the "Do URL" is clicked. This is what the url would look like:

    Code:
    http://yoohoo.com/login_whatever.php?username=USERNAME&password=PASSWORD
    Where you see the uppercase username and password is where I want to add the values from the login fields. Here's the code I'm using now for the form:

    http://area52.heliohost.org/misc/url_form.html

    Thanks for any help.
    Last edited by byrondallas; 12-03-2012 at 08:58 AM.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,613
    Thanks
    80
    Thanked 4,634 Times in 4,596 Posts
    Making it way way way too hard.

    No JavaScript needed, at all.

    Boiled down to the bare essentials:
    Code:
    <form method="get" action="http://yoohoo.com/login_whatever.php">
    <input type="text" name="u" size="25">
    <input type="text" name="username">
    <input type="text" name="password">
    <input type="submit" value="Go">
    </form>
    I don't know what the purpose of your name="u" field is, but it *TOO* will be send along to login_whatever.php as part of the URL.

    If you don't need/want it, then omit it.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    New Coder
    Join Date
    Jul 2011
    Location
    USA
    Posts
    39
    Thanks
    0
    Thanked 1 Time in 1 Post
    I wish it were that simple, but I really need the javascript to place the username and password inside the url. I fully understand what your saying, but that won't work for this particular application.

    Quote Originally Posted by Old Pedant View Post
    I don't know what the purpose of your name="u" field is, but it *TOO* will be send along to login_whatever.php as part of the URL.
    It has to do with this function (not written by me btw):

    Code:
    function doIt(v_al)
    {
    var t_a1 = document.forms["theform"].elements["u"];
    if (t_a1.value.indexOf(v_al) == -1)
    {
    t_a1.value += v_al;
    }
    }
    When you click the Do Url button, it loads the url inside this url textfield:

    Code:
    <input type="text" name="u" size="25">
    So what I need to happen is when the person enters the username and password and clicks Do Url, the url gets loaded into the url textfield with the username and password in the url. So that the url would look like this in the url field:

    Code:
    http://yoohoo.com/login_whatever.php?username=USERNAME&password=PASSWORD
    Of course where you see the uppercase USERNAME and PASSWORD, that's where I need the javascript to pass the username and password values from the login form.

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,613
    Thanks
    80
    Thanked 4,634 Times in 4,596 Posts
    So you aren't showing us real code?

    Because *clearly* this <form> is useless:
    Code:
    <form action="" method="post" name="theform">
    It posts back *TO THE SAME PAGE* and it uses method="post", which means that even if we do all that you ask, you will end up sending the following POST data back to this same page:
    Code:
    http://localhost/dearabby/junk1.html?u=http%3A%2F%2Fyoohoo.com%2Flogin_whatever.php%3Fusername%3Dasdfa+asdf%26password%3DNAX234&submited=Go&username=asdfa+asdf&password=NAX234
    Which is (a) illegal because an HTML page can't receive POSTed data and (b) incredibly redundant, because you will be sending the username and password info *TWICE*.

    SO... It would help if you would use *REAL* code instead of giving us fake code that is somewhat meaningless.

    I would *GUESS* that what you are really after is *SOMETHING* like this:
    Code:
    <html>
    <head>
    <title>Untitled Document</title>
    <script type="text/javascript">
    function doIt(btn, url)
    {
        var form1 = btn.form;
        url += "?username=" + form1.username.value;
        url += "&password=" + form1.password.value;
        var form2 = document.getElementById("theRealForm");
        form2.u.value = url;
        form2.submitted.focus();
    }
    </script>
    </head>
    <body>
    <br><br>
    <br><br>
    <table align="center" border="0" cellspacing="10">
    <tr>
    <td align="center" colspan="2">
    <form action="somepage.php" method="post" id="theRealForm">
    <input type="text" name="u" size="25">
    <input type="submit" name="submited" value="Go">
    </form>
    </td>
    </tr>
    <form id="dummyForm">
    <tr>
    <td align="right">Username:</td><td><input type="text" name="username">
    </td>
    </tr>
    <tr>
    <td align="right">Password:</td><td><input type="text" name="password">
    </td>
    </tr>
    <tr>
    <td align="center" colspan="2">
    <input type="button" name="theform" value="Do URL" 
           onclick="doIt(this,'http://yoohoo.com/login_whatever.php');">
    </form> 
    </td>
    </tr>
    </table>
    </body> 
    </html>
    Though presumably with all sorts of other stuff you didn't show us.

    No?
    Last edited by Old Pedant; 12-03-2012 at 09:40 PM.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #5
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Whatever values you set in the form from JavaScript will need to be redone on the server after the form is submitted for those people without JavaScript so you should get that version working first and then decide if there will be sufficient time saving for those with javaScript if you implement something in JavaScript.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #6
    New Coder
    Join Date
    Jul 2011
    Location
    USA
    Posts
    39
    Thanks
    0
    Thanked 1 Time in 1 Post
    Quote Originally Posted by Old Pedant View Post
    So you aren't showing us real code?
    SO... It would help if you would use *REAL* code instead of giving us fake code that is somewhat meaningless.
    I'm showing you the code I'm using, just not the end result. I guess I should explain and maybe it will help shed some light on what's going on. The doIt function is on a proxy. All it does is drop the url into the url form and then you click the proxy submit button to submit the url. This is being used by people who are on a really old browser called webtv and they can't handle secure communications without going through a proxy. The site they want to go to is fastmail.fm, but just going to fastmail.fm through the proxy by entering this url https://fastmail.fm fails for them because fastmail is using this as the form action <form action="/">. Every time they submit the login info through the proxy, it just takes them back to the proxy home page instead of there mail page. The doIt function was already on the proxy page and it just dropped in the fastmail url into the proxy form but like I explained previously, fastmail has changed thier form action. So after some testing I found a way for them to get back to thier fastmail email by entering this into the proxy form:

    Code:
    https://www.fastmail.fm/?dologin=1&page=m.html&interface=html&screenSize=mobile&hasPushState=0&username=USERNAME&password=PASSWORD
    So what it all boils down to is that I want the users to be able to enter thier username and password and click doIt and the url (above) get's entered into the proxy form with thier username and password in the url. Then they click submit and the proxy takes care of the secure communications for them.

    LOL it wasn't that I was hiding anything, it was just to much to have to explain.

    Quote Originally Posted by Old Pedant View Post
    I would *GUESS* that what you are really after is *SOMETHING* like this:
    YES! That's exactly what I'm after. Thank you so much for your help!
    Last edited by byrondallas; 12-04-2012 at 12:45 AM.

  • #7
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,613
    Thanks
    80
    Thanked 4,634 Times in 4,596 Posts
    Sorry, I didn't mean you were trying to conceal stuff from us, just that there was no way the code, as you showed it, could work.

    It still can't work as you showed it, if the page you showed us really is an HTML page, for the reasons I gave you.

    But hopefully now you can use some of what I showed to make it work?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #8
    New Coder
    Join Date
    Jul 2011
    Location
    USA
    Posts
    39
    Thanks
    0
    Thanked 1 Time in 1 Post
    The proxy is a php page. The page I posted was just an example of what's on the proxy page. I really didn't want to post the proxy nor would you have been able to view it unless I changed the htaccess to allow more than webtv people. Anyway the code you posted works perfect for my application!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •