Passing input value in URL

A place to discuss the implementation and style of computer programs.

Moderators: phlip, Moderators General, Prelates

Passing input value in URL

Postby b1ackcat » Mon Sep 19, 2011 4:37 pm UTC

Hello Coding!

So I have a website that I'd like to point to in an app I'm writing. I'd like to pass it a value from my app, but the site, to my knowledge, has no API and I would just be hard-linking to the page. There's a text field on this page that I would like to populate using my link, similar to how you can set variables using php with ?field=xxx

Is there a way to just do this with the URL if I know the ID of the textbox (from the page source)?
My favorite Churchill quote: "The best argument against democracy is a five-minute conversation with the average voter."
User avatar
b1ackcat
 
Posts: 274
Joined: Mon Oct 20, 2008 4:35 pm UTC

Re: Passing input value in URL

Postby Xanthir » Mon Sep 19, 2011 4:45 pm UTC

No. The url query (the part after the ?) is just data made available to the server and the page. It doesn't have any effect by itself.
(defun fibs (n &optional (a 1) (b 1)) (take n (unfold '+ a b)))
User avatar
Xanthir
My HERO!!!
 
Posts: 4021
Joined: Tue Feb 20, 2007 12:49 am UTC
Location: The Googleplex

Re: Passing input value in URL

Postby b1ackcat » Mon Sep 19, 2011 4:49 pm UTC

Bah. Makes sense. Alright, I'll contact the site admin to see if there's some interface I can use. Thanks.
My favorite Churchill quote: "The best argument against democracy is a five-minute conversation with the average voter."
User avatar
b1ackcat
 
Posts: 274
Joined: Mon Oct 20, 2008 4:35 pm UTC

Re: Passing input value in URL

Postby Steax » Mon Sep 19, 2011 5:05 pm UTC

I'm pretty sure you could also embed the page in an iframe and use javascript to populate the input field.
In Minecraft, I use the username Rirez.
User avatar
Steax
SecondTalon's Goon Squad
 
Posts: 2770
Joined: Sat Jan 12, 2008 12:18 pm UTC

Re: Passing input value in URL

Postby You, sir, name? » Mon Sep 19, 2011 5:16 pm UTC

You can pass this information to the web browser using the URL hash tag.

Something like

http://www.example.com/foobar/#field=data

And then use javascript to grab the information and insert it in the field. Probably easiest to use jQuery or some such to get it done.
Blag.
Ternary computer emulator. Latest version is 0.5 [Nov 29 2008].

Good morning, that's a nice tnetennba.
User avatar
You, sir, name?
 
Posts: 6178
Joined: Sun Apr 22, 2007 10:07 am UTC
Location: Chako Paul City

Re: Passing input value in URL

Postby Xanthir » Mon Sep 19, 2011 5:24 pm UTC

There is no difference (to javascript) between passing it in the query or passing it in the hash. Both are available from javascript.

However, b1ackcat doesn't have access to the page's source, and so can't add code to deal with that information.
(defun fibs (n &optional (a 1) (b 1)) (take n (unfold '+ a b)))
User avatar
Xanthir
My HERO!!!
 
Posts: 4021
Joined: Tue Feb 20, 2007 12:49 am UTC
Location: The Googleplex

Re: Passing input value in URL

Postby You, sir, name? » Mon Sep 19, 2011 6:16 pm UTC

While both are available, it's bad practice to send message to the client via the query unless you also intend for the server to receive the message. The Bad Thing that may happen when ignoring this separation is that the server may or may not in the future start reacting to this query variable.
Blag.
Ternary computer emulator. Latest version is 0.5 [Nov 29 2008].

Good morning, that's a nice tnetennba.
User avatar
You, sir, name?
 
Posts: 6178
Joined: Sun Apr 22, 2007 10:07 am UTC
Location: Chako Paul City


Return to Coding

Who is online

Users browsing this forum: No registered users and 13 guests