Skip to content Skip to sidebar Skip to footer

HTML - How To Pre-populate Form Field With Known Value Upon Load?

I have this web page, say Home.html, that has links to other employee-related web sites. There is one, say www.SomeSite.com/HR.xyz, where it has a form to login. There are 3 fiel

Solution 1:

Change the value attribute:

<input autocomplete='off' class='loginInput' tabindex='3' type="text"
name="company" id="company" value="MyCo" maxlength='50' size="25">

Solution 2:

You could try using a get request to populate the input box in the form. That's only if the url like you said is as such www.SomeSite.com/HR.xyz?company=MyCo. In PHP you would simply include:

<input autocomplete='off' class='loginInput' tabindex='3' type="text" name="company" id="company" value="<?php echo $_GET["company"]; ?>" maxlength='50' size="25">

As you can see that within the value attribute is a echo statement that echoes the get request in the URI where HR.xyz?company=MyCo contains the company get request. If you are using just pure html with no scripting language like php the only other method is by having this code:

<input autocomplete='off' class='loginInput' tabindex='3' type="text" name="company" id="company" value="myCo" maxlength='50' size="25">


Solution 3:

If your users universally use Internet Explorer, you could do something a bit hackish with VBScript, e.g.

Set IE = CreateObject("InternetExplorer.Application")

IE.Navigate "http://www.SomeSite.com/HR.xyz"

IE.Visible = True

IE.Document.All.Item("company").Value = "MyCo"

But that would be hard to distribute to your users because they would have to click through some security errors, and it requires IE.

If they're Firefox users I would suggest looking into Mozilla Autofill.


Solution 4:

You need some way of reading the value passed in the URL on the HR.xyz page. You need to either use Javascript or some server side logic (PHP, .NET, etc)


Post a Comment for "HTML - How To Pre-populate Form Field With Known Value Upon Load?"