从按钮预填充 HTML 表单
我希望这个问题对于任何了解 JS 和 HTML 的人来说都有一个明显的答案:)
我有一个非常具体的问题。我正在尝试添加到网站按钮的标题中,该按钮的功能类似于“快速搜索”,基本上单击后会将预填充的表单值发送到我的搜索页面,并且搜索页面也会在 ajax 表单中填充这些值。
以下是结果页面之外的示例搜索页面: http://www.thediamondsexperts.com/index.php?route=product /diamondsearch/jewelry
您会注意到,当您更改此处的值并单击“搜索”时,这些值也会以 ajax 形式显示在搜索结果页面的侧边栏上。
我只想做的是为预设搜索创建不同的变体,并将它们作为按钮放在标题中。
当我尝试放入一些不可见的表单时,它不会工作,因为多个表单值具有相同的 id,但总的来说,我认为必须有一种简单的方法来执行此服务器端操作。
例如,复制接受搜索的当前函数,为其添加预设值,而不是从表单填充值,然后简单地调用该函数 onClick。这有道理吗?
我需要创建一些足够简单的东西,尽管管理员以后可以轻松更改和自定义更多按钮,因此客户端解决方案将是最好的。
非常感谢您的帮助!
I hope this question has an obvious answer to anyone who knows his way around JS and HTML :)
I have a very specific problem. I am trying to add to the header on a site buttons that will function like 'quick searches' which will basically on click send pre-filled form values to my search page and have the search page also populate these values in the ajax form inside.
Here is a sample search page that's outside of the results page:
http://www.thediamondsexperts.com/index.php?route=product/diamondsearch/jewelry
You'll notice that when you change the values there and click Search, the values also appear in the ajax form on the sidebar of the search results page.
What I simply want to do is create different variations for pre-set searches, and put them as buttons in the header.
When I try to put a few invisible forms in it won't work because of the multiple form values with the same ids but in general I think there must be a simple way to do this server side.
For instance, copy the current function that accepts the search, have it with pre-set values instead of populating the values from the form and then simply calling that function onClick. Does that make sense?
I need to create something simple enough though that would be easy for the admin to later change and customize more buttons so a client-side solution would be best.
Your help is much appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您所需要的只是一个带有隐藏输入和提交按钮的表单:
这只会显示按钮,但值仍会发送到表单的操作。
不是真的,至少对我来说不是。如果您能澄清,我很乐意提供更多帮助。
当您说“具有相同 id 的多个表单值”时,我担心您可能会感到困惑:表单输入不需要有“id”,我认为您的意思是“名称”,并且不需要有多个表单中具有相同名称的输入,除非您想要 发送值数组。
我不想过多谈论 ajax 在该网站上的工作原理,因为那完全是另一回事,而您似乎关心的只是预设的搜索按钮。希望这可以帮助你解决这个问题,GL。
编辑:我很难弄清楚您真正要问的是什么,如果您尝试复制该网站上的行为,请告诉我们您可以使用哪种服务器端语言,如果您正在使用或愿意使用任何 javascript 库,以及到目前为止您已经尝试过的内容。完整的勺子喂养教程确实超出了范围,如果您分享当前尝试的代码,您将获得更好、更清晰的帮助。
All you need is a form with hidden inputs and a submit button:
This will only show the button, but the values will still be sent to your form's action.
Not really, not to me at least. If you can clarify I'd be glad to help more.
When you say "multiple form values with the same ids", I fear you may be confused: There is no requirement for a form input to have an "id", I think you mean "name", and there's no need to have multiple inputs with the same name in a form unless you want to send an array of values.
I didn't want to go overboard and talk about how the ajax works on that site, because that's another thing altogether and all you seemed to be concerned about was the preset search buttons. Hopefully this helps you figure it out, GL.
EDIT: I'm having a tough time figuring out what you're really asking, if you are trying to duplicate the behavior on that site, please tell us what server side language is available to you, if you're using or open to using any javascript libraries, and what you have tried so far. A full fledged spoon-feeding tutorial is really out of scope, you will get better, clearer help if you share the code from your current attempts.
如果您想将值从一个页面传递到另一个页面并在客户端处理它,请使用“get”作为表单提交方法,并使用方便的“gup()”函数来获取参数值。您可以在此处获取有关 gup() 的更多信息:
在初始页面上,您可以使用输入使用 type="hidden" 或仅从可见输入中获取值(如示例页面上所示)。然后提交到您的结果页面。给定一个带有类似内容的初始页面...
...这是结果页面的示例用法:
然后只需将这些值分配给您想要的任何元素,例如输入:
If you want to pass values from one page to another and handle it client-side, use "get" for the form submit method, and use the handy "gup()" function to grab the param values. You can get more info on gup() here:
On your initial page, you can either use inputs with type="hidden" or just get the values from the visible inputs (as on your sample page). Then submit to your results page. Given an initial page with something like this...
... here's sample usage for the results page:
Then simply assign those values to whatever elements you want, e.g. an input: