0

How can I construct a URL that will automatically fill in a field on the target page, when the field doesn't have an ID? The field I need to populate has code that looks like this:

 <input type="text" name="subject" size="40" maxlength="255" onchange="max255(this)">

Using an answer that I found here, I created an HTML page that uses jQuery to construct a URL based on what input a user types into a field. Then when you click a button, it goes to that URL, with the user input added to the end of the URL.

What I need it to do now is fill that field in the target page, with what the user entered in the field.

The normal link to the target page is similar to this:

 xxx.com/bin/tools/new_view.cgi?type=11111

I think that If the field I want to populate had an ID, let's say the ID was also "subject", then it might be a matter of just modifying my jQuery code so that my generated URL was:

 xxx.com/bin/tools/new_view.cgi?type=1111#subject=what was typed into the form on my page

This doesn't work however, because subject is the field's name, not its ID.

If I inspect that element on the target page, and modify it by adding a value, like this:

<input type="text" name="subject" size="40" maxlength="255" onchange="max255(this)" value="My Text">

then I see My Text filled in the field (until I reload the page anyway).

Is there any way to target and populate that field as it is now? Or do I have to get them to add an ID to that field?

Community
  • 1
  • 1
user3762977
  • 651
  • 2
  • 15
  • 27
  • If you don't want to use an id you can use `input[name="subject"]` to target the field. However, you really should just use an id, that's what the id is for. – imtheman Feb 21 '15 at 00:04
  • Thanks. Well it's not my page, I mean someone else created and controls that page, and getting them to change it would take some doing, but I'll try. In the meantime, so what would do you add to the regular URL, #input[name="subject"] then where does the field input go? – user3762977 Feb 21 '15 at 00:11
  • possible duplicate of [Selecting element by data attribute](http://stackoverflow.com/questions/2487747/selecting-element-by-data-attribute) – imtheman Feb 21 '15 at 00:11
  • If you don't own the target page, and the target doesn't provide an API for taking URL query parameters as input for fields, you can't do this. That said, some web servers will autofill data from URL query parameters exactly as you want; you'll just have to experiment to see whether your target page allows it. – Palpatim Feb 21 '15 at 00:27
  • Palpatim: Okay that's what I really needed to know, is this even possible. Nothing I've tried has any effect. But then I can't find any forms with ID on the page, so I can't test with that, which I at least know how to do. I don't own the page but it is in the same company, so I'll see what they can do to provide what I need. Thx – user3762977 Feb 21 '15 at 00:45

1 Answers1

0

This was simple in the end, and I was closer than I thought with the original question. The reason that appending #subject=what was typed... to the URL didn't work is because subject wasn't an ID, as I said. All I had to do however was use & instead of #

 xxx.com/bin/tools/new_view.cgi?type=1111&subject=what was typed

and that URL fills the target page field named subject with the string "what was typed"

user3762977
  • 651
  • 2
  • 15
  • 27