HTML - How to pre-populate form field with known value upon load?

前端 未结 4 1836
长情又很酷
长情又很酷 2020-12-18 19:34

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

相关标签:
4条回答
  • 2020-12-18 19:56

    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">

    0 讨论(0)
  • 2020-12-18 19:57

    Change the value attribute:

    <input autocomplete='off' class='loginInput' tabindex='3' type="text"
    name="company" id="company" value="MyCo" maxlength='50' size="25">
    
    0 讨论(0)
  • 2020-12-18 20:02

    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)

    0 讨论(0)
  • 2020-12-18 20:05

    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.

    0 讨论(0)
提交回复
热议问题