How do I submit a form with a <li> instead of a submit button? - forms

I want to be able to submit a form but instead of having to click on a submit button, I'd like to be able to click on an <li> element and have it submit.
Any help would be GREAT!
Thanks in advance!
Ncoder

You could put an onclick event on the LI that calls the forms submit event:
<form id="myForm" action="foo.htm" method="post">
<ul>
<li onclick="myForm.submit();">Click me</li>
</ul>
</form>
Your form would be non-standard and not very accessible though.

<li onclick="formName.submit();">
Although the above method will work, it seems such a strange requirement, and I'd advise re-thinking the logic behind the program.

JavaScript.
Wire the onclick event of the element. Get a reference to the form.
var frm = document.getElementById('formid');
Submit it.
frm.submit()

Add click handler on <li> element and use javascript to submit the form document.getElementById('formid').submit();

<form id="myForm">
...
<li id="something" onclick="mySubmit();"><p>hello world!</p></li>
...
</form>
<script type="text/javascript">
function mySubmit(){
document.getElementById("myForm").submit();
}</script>

I believe I was attempting to accomplish something quite similar to you, but I decided to code it the "correct" way. Here is an alternative approach that basically stylizes the submit button like an li element.
HTML/Coldfusion
<div id="student_options">
<ul>
<cfoutput query="student_specs">
<cfif #currentStudent# IS NOT #student_specs.GS1FNFP#>
<form action="" method="POST" name="dropdown">
<input type="hidden" name="change_stnum" value="#Trim(student_specs.STNUM)#" />
<input type="submit" name="submit_stu_change" value="#Trim(student_specs.GS1FNFP)#" />
</form>
</cfif>
</cfoutput>
</ul>
</div>
CSS
#student_options input[type="submit"] {
padding:15px 20px 15px 20px;
font-size:90%;
color:#555;
background-color:#eee;
display:block;
width:100%;
text-align:left;
}
#student_options input[type="submit"]:hover {
background-color:#F4F4F4;
cursor:pointer;
}
You will have to customize elements to your liking, but this is a better approach than using javascript to submit the form.

Related

Pushing Typed text into data Layer GTM - No submit button

I am trying to measure engagement (capture text input, send value into GTM data layer etc.) when a visitor clicks on dropdown and type into the text box (see screenshot).
The problem is, there is no submit button. Search and display is performed automatically. Wondering, is even possible to push entry text into GTM Data layer?
Form screenshot
Here is the part of the script
<div class="dropdown-menu open" style="max-height: 481.5px; overflow: hidden; min-height: 151px;">
<div class="bs-searchbox"><input type="text" class="form-control" autocomplete="off"></div>
<ul class="dropdown-menu inner" role="menu" style="max-height: 420.5px; overflow-y: auto; min-height: 90px;">
<li data-original-index="1" class="">
<a tabindex="0" class="indent-1 location-name" style="" data-tokens="null">
<span class="text">All Destinations</span><span class="fa fa-checkmark check-mark"></span>
</a>
</li>
<li data-original-index="2" class=""><a tabindex="0" class="indent-1 location-name js-state-AL" style="" data-tokens="null"><span class="text">Alabama</span><span class="fa fa-checkmark check-mark"></span></a></li>
.
.
.
.
.
</ul>
</div>
You can do this via custom HTML tag. In the tag you write a custom listener for the keydown browser event. It's slightly complicated but described very well in the link below by simo ahava.
https://www.simoahava.com/analytics/track-autocomplete-search-google-tag-manager/
Hope that helps.

How to add button handler in Scala Play framework?

I'm using scala play framework + scala template engine for front end. How can I add button handler? I need to call some function when clicking on it.
<body>
<p>Database interface<br />
<textarea style="margin: 0px; height: 193px; width: 533px;" cols="40" name="comment" rows="3"></textarea>
</p>
<p><input type="submit" value="Select" /> <input type="submit" value="Insert" /> <input type="submit" value="Update" /></p>
</body>
There is no special button handlers. You can write it in Javascript or plain HTML. The only trick thing is to get a link the server function. You can get the link automatically by reverse routing.
For example you have the route
GET /count controllers.CountController.count
Then you can get the link by calling controllers.routes.CountController.count in your code.
In the template engine, link:
Count
Plain HTML button:
<form action="#controllers.routes.CountController.count">
<input type="submit" value="HTML only" />
</form>
Button with Javascript:
<input type="submit" onclick="location.href='#controllers.routes.CountController.count';" value="Javascript" />
If you need some special thing on the client side to process then you need to write your own code in Javascript.
There's nothing in Scala/Play/Twirl that would handle button clicks, the simplest approach would be to use jQuery .click()

How HTML Form Tag Effect on search result

I wonder if form tag wrapping div contents will effect on search engines result (like Google,bing,yahoo)
<form onsubmit="return oQuickModify.bInEditMode ">
<div class="post">
<div id="msg_4" class="inner">
Post contents here ....
............
............
</div>
</div>
</form>
^^ this is SMF board post viewing format
It will have no effect whatsoever.

My HTML5 form displays inline and without line breaks

I'm doing this HTML5 form, but when I check it on the browser (running it locally) it displays the label next to the input space next to le label and so.
heres the code:
<form>
<label for="name">Nombre:</label>
<input type="text" id="name" placeholder="Ingresa tu Nombre" required />
<label for="email">Email:</label>
<input type="email" id="email" placeholder="Ingresa tu e-mail " required />
<label for="message">Mensage:</label>
<textarea id="message" placeholder="Ingresa tu Mensaje" required></textarea>
<input type="submit" value="Envia tu mensage" >
</form>
should I use <br />? I already checked on other web pages and they dont use it
thank you.
As Kolink pointed out, the form displays inline as all the elements inside it are inline.
You shouldn't be using <br/> or <p> as they are not intended for that purpose (You shouldn't be using a toothbrush to clean a toilet). Better use a <ul> with <li> for each field. This makes sense as the form is nothing but a list of fields.
The mark-up would be like this:
<form>
<ul>
<li>
<label for="something">some label</label>
<input id="something" />
</li>
</ul>
</form>
Alternatively, you can go ahead and use <div> as well (but not <p>).
Well, <label> is inline, <input> is inline, <textarea> is inline...
If all your elements are inline, of course your overall form will be.
Try using the <br /> tag, or maybe <p>...</p>.
Kolink is correct. Another way to address this is to add
display: block;
to all input and label elements using CSS.

How do I click on a button in Selenium IDE using only the text associated with the button and not its position?

this is the dom source of the button I want to click on
<div class="footer clearFloat">
<div class="left">
</div>
<div class="right">
[P]
[-575063738]
[SB_XML]
<input class="button" value="Next step" id="dpTransportResultSelectLink[7]" type="submit">
</div>
</div>"
This is the x-path "/html/body[#id='transport-results']/div[#id='master']/div[#id='master_center']/div[#id='page_content']/div[#id='contentPad']/form[#id='fare_5']/div[2]/div[2]"
How do I frame my locator using "[SB_XML]", irrespective of the form Id?
//*[contains(text(),'[SB_XML]')]/following-sibling::input[1]
I've tested it as an xpath but not in Selenium
lemme know how it goes