Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-02-2012, 10:55 PM   PM User | #1
byrondallas
New Coder

 
Join Date: Jul 2011
Location: USA
Posts: 39
Thanks: 0
Thanked 1 Time in 1 Post
byrondallas is an unknown quantity at this point
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 07:58 AM..
byrondallas is offline   Reply With Quote
Old 12-03-2012, 06:43 AM   PM User | #2
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,168
Thanks: 59
Thanked 3,993 Times in 3,962 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is offline   Reply With Quote
Old 12-03-2012, 08:11 AM   PM User | #3
byrondallas
New Coder

 
Join Date: Jul 2011
Location: USA
Posts: 39
Thanks: 0
Thanked 1 Time in 1 Post
byrondallas is an unknown quantity at this point
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.
byrondallas is offline   Reply With Quote
Old 12-03-2012, 08:38 PM   PM User | #4
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,168
Thanks: 59
Thanked 3,993 Times in 3,962 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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?
__________________
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.

Last edited by Old Pedant; 12-03-2012 at 08:40 PM..
Old Pedant is offline   Reply With Quote
Old 12-03-2012, 08:47 PM   PM User | #5
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,447
Thanks: 0
Thanked 496 Times in 488 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
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/
felgall is offline   Reply With Quote
Old 12-03-2012, 11:23 PM   PM User | #6
byrondallas
New Coder

 
Join Date: Jul 2011
Location: USA
Posts: 39
Thanks: 0
Thanked 1 Time in 1 Post
byrondallas is an unknown quantity at this point
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-03-2012 at 11:45 PM..
byrondallas is offline   Reply With Quote
Old 12-03-2012, 11:49 PM   PM User | #7
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,168
Thanks: 59
Thanked 3,993 Times in 3,962 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is offline   Reply With Quote
Old 12-03-2012, 11:57 PM   PM User | #8
byrondallas
New Coder

 
Join Date: Jul 2011
Location: USA
Posts: 39
Thanks: 0
Thanked 1 Time in 1 Post
byrondallas is an unknown quantity at this point
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!
byrondallas is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:27 PM.


Advertisement
Log in to turn off these ads.