i want to type a numerical value in a text box and after i type it i want it to be assigned to a JavaScript variable instantly without submitting it
so the idea is
type a number
var x = that number instantly
Here is the html
<form id="tools">
<input type="text" id"stk"/>
</form>
now what is the javascript? :D
you can achive that assigning an a handler for the event (onKeyUp)... and that handler should assign the value to the variable. I suggest you to use jQuery instead of pure javascript.
With jQuery should look like this:
var x = 0;
$('#textbox-name').onkeypress(function({
x = $(this).attr('value');
}));
Sorry if I made a mistake with the syntax, but that's the main idea.
Your Jsp :
<form action="someAction" method="post">
<input type="text" name="text" id="text" />
<input type="text" name="value" id="value" />
</form>
Java Script needed is :
var myVar=setInterval(function(){getValue()},5000);
function getValue()
{
document.getElementById("value").value=document.getElementById("text").value;
}
By this type of JavaScript function the value of the text field will be received by JavaScript for every 5 Seconds . If you need instantly you can replace 5000 with 0. I think its little bit clumsy try to understand it
Related
there is this piece of code that provides a checkbox following from a link to the T&C.
<div class="checkbox accept_agreement">
<label class="control-label" for="step_data_accept_agreement">
<input type="hidden" name="step_data[accept_agreement]" value="0">
<input type="checkbox" name="step_data[accept_agreement]" id="step_data_accept_agreement" value="1">
<label for="step_data_accept_agreement">
<a target="_blank" href="/lanevillkor/">
<font><font>I agree, have read and stored the terms and conditions</font></font>
</a>
</label>
</label>
</div>
Now, I am working on a spock test using geb, and I try to retrieve the checkbox element
<input type="checkbox" name="step_data[accept_agreement]" id="step_data_accept_agreement" value="1">
to do so i have tried many things without the expected output. i was expected that something like
$("#step_data_accept_agreement").click() would be pretty straight forward but it is not. in the other side if I put $("[for='step_data_accept_agreement'] label").click() it clicks the link.
I tried to become as more specific but nothing looks to return the element correctly.
one of my last attempts was
termsAndConditionsOption(wait: true) { $("#step_data_accept_agreement", name: "step_data[accept_agreement]") }
and the error message, as in the other cases too, was in one sentence
element not visible
What do I miss?
So the solution was to use js to click the checkbox. The simpliest way is:
def agreeOnTermsAndConditionsAccept() {
String mouseClickEvt = """
var evt = new MouseEvent('click', {
bubbles: true,
cancelable: true,
view: window
});
arguments[0].dispatchEvent(evt);
"""
browser.js.exec(termsAndConditionsOption.firstElement(), mouseClickEvt)
}
Geb provides js support to work with javascript, as we find in the documentation. Also another link shows how to simulate a click event with pure javascript.
This was required as the checkbox cant be found as it is hidden. With javascript we can 'see' the position of the element and perform an action in the location that we want. iniMouseEvent can be used as well as it is documentanted here
I'm using the TYPO3 version 8, I have installed the indexed_search form box with typoscript
50 = COA
50 {
stdWrap {
wrap = <div id="searchcontainer">|</div><div class="clearboth"></div>
required = 1
}
10 = TEXT
10 {
wrap = <form id="searchbox" name="searchbox" action="|" method="post">
typolink.parameter = {$searchPID}
typolink.returnLast = url
if.isTrue = {$config.tx_realurl_enable}
}
20 = TEXT
20 {
value = <form id="searchbox" name="searchbox" action="/" method="post">
if.isFalse = {$config.tx_realurl_enable}
}
30 = COA
30 {
10 = TEXT
10{
wrap = <input type="hidden" name="id" value="|" />
value = {$searchPID}
if.isFalse = {$config.tx_realurl_enable}
}
20 = TEXT
20 {
wrap = <input type="text" id="swords" name="swords" value="|" size="20" onfocus="this.value='';" />
value = {$searchTEXT}
}
30 = TEXT
30 {
wrap = <input type="submit" id="searchbutton" value="" />
}
}
40 = TEXT
40 {
value = </form>
}
}
When I click on search, I'm redirected to my search page wich contain the search plugin installed, but no search results or even the keyword is showing. The pages are well indexed and in the backend indexing searched keyword it appears, but not in the frontend, what I'm mising here ? please help!
user2714261 shows, how to deactivate the cHash check for all elements. That might a bit risky in deed. But you can deactive it only for the indexed_search plugin. That won't be any problem, because the indexed_search should not cache anyway. So you jsut can write in your plugin-Setup:
plugin {
tx_indexedsearch {
features.requireCHashArgumentForActionArguments = 0
}
}
That worked fine in TYPO3 8.7.9.
Martin
You can use <f:form> in a FLUIDTEMPLATE to generate a Quicksearch-Form. This way an essential cHash-parameter will be generated and appended to the action-URL, automatically.
TypoScript (Constants)
plugin.tx_indexedsearch.settings.targetPid = 35
TypoScript (Setup)
lib.quicksearch = FLUIDTEMPLATE
lib.quicksearch{
file = fileadmin/Quicksearch.html
settings.targetPid = {$plugin.tx_indexedsearch.settings.targetPid}
}
Quicksearch.html
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true">
<div id="quicksearch">
<f:form action="search" method="post" controller="Search" extensionName="indexedsearch" pluginName="pi2" pageUid="{settings.targetPid}">
<f:form.textfield name="search[sword]" value="{sword}" class="quicksearch-sword" />
<f:form.submit name="search[submitButton]" value="Search" class="quicksearch-submit" />
</f:form>
</div>
</html>
Edit: i found the solution. You have to add something to the typolink ts (my result plugin has _pi2 btw)
wrap = <form id="searchbox" name="searchbox" action="|" method="post">
typolink.parameter = 25
typolink.additionalParams = &tx_indexedsearch_pi2[action]=search&tx_indexedsearch_pi2[controller]=Search
typolink.returnLast = url
typolink.useCacheHash = 1
First Posting:
I don't have the solution right now, but i found something that could help.
I'm having a similar problem with TYPO3 8 and a searchbox. I adapted my HTML of the searchbox, that it fits to the embedded plugin, like this:
<form action="searchresult.html?tx_indexedsearch_pi2%5Baction%5D=search&tx_indexedsearch_pi2%5Bcontroller%5D=Search" method="post" name="searchform" id="searchform">
<input name="tx_indexedsearch_pi2[search][sword]" type="text"/>
<input name="tx_indexedsearch_pi2[search][submitButton]" type="submit" id="submitbutton" value="submit"/>
...
As you can see i have a fixed setup here in my template. What i noticed is, that the embedded plugin obviously doesn't run if you don't send the chash in the action url. Probably you can generate it with your typoscript.
I'm just sure that this is the problem, at least for my case, because when i turn the chash requirements for extbase off, it works ...
config.tx_extbase.features.requireCHashArgumentForActionArguments = 0
but i believe that is a little bit risky and should not be used in production
so generating the chash should be the way to do make it work. just wanted to share what i found out.
Am using an html form to send data to a sql database using php.
My trouble is that I have a dynamic value for number of items which changes for each order and am trying to avoid having to add an x number of extra text fields for all orders.
A better solution would be to enter a value in a text field which then makes the same number of additional text fields appear in the form.
Is there anyway to accomplish this?
Thanks
OK. So you want to show a number of input fields at the user's request, before pressing the submit button. My first approach would be to do it in javascript.
Let's assume this form:
<form>
<p><input name="myInput1" /></p>
<button type="submit">submit</button>
</form>
You could include an extra button to add a new row:
<form>
<p><input name="myInput1" /></p>
<button type="button" onclick="addInput(this.form)">add input</button>
<button type="submit">submit</button>
</form>
... and the handler function would be something like this:
<script type="text/javascript">
function addInput(form)
{
// Create a new <p><input> node at the end of the form, throughput the DOM API:
// Get the last <p> element of the form
var paragraphs=form.getElementsByTagName("P")
var lastParagraph=paragraphs[paragraphs.length-1]
// Create a new <p> element with a <input> child:
var newParagraph=document.createElement("P")
var newInput=document.createElement("INPUT")
// Name the <input> with a numeric suffix not to produce duplicates:
newInput.name="myInput"+(1+paragraphs.length)
newParagraph.appendChild(newInput)
// Add the created <p> after the last existing <p> of the form:
form.insertBefore(newParagraph, lastParagraph.nextSibling)
}
</script>
(Notice that all the rendering logic is performed in the client side (in HTML + javascript), and when the form is finally submitted, the server will just receive a collection of pairs name + value.)
If I have a text and I only want to allow the user enter text between 5 and 10 characters long, how do I do this using javascipt?
I have tried using mix and max functions but they only works for numeric data.
You could do something like this:
`
function checkLength(){
var textbox = document.getElementById("textbox");
if(textbox.value.length <= 10 && textbox.value.length >= 5){
alert("success");
}
else{
alert("make sure the input is between 5-10 characters long")
}
}
</script>
<input type="text" id="textbox"></input>
<input type="submit" name="textboxSubmit" onclick="checkLength()" />
`
You need to use the maxlength attribute for input fields, something like this should do it:
<input name="myTextInput" type="text" maxlength="5"></input>
You can use "maxlength" attribute to not allow more than x characters & do validation using javascript for min length.
see this example: http://jsfiddle.net/nZ37J/
HTML
<form id="form_elem" action="/sdas" method="post">
<input type="text" id="example" maxlength="10"></input>
<span id="error_msg" style="color:red"></span>
<input type="button" id="validate" value="validate"></input>
</form>
Javascript:
$("#validate").click(function(){
var inputStr = $("#example").val();
if(inputStr.length<5)
$("#error_msg").html("enter atleast 5 chars in the input box");
else
$("#form_elem").submit();
})
I did a bit of a mix of the samples above trying to make it as simple as possible and avoid unnecessary alerts.
Script:
function checkLength(){
var textbox = document.getElementById("comment");
if(textbox.value.length <= 500 && textbox.value.length >= 5){
return true;
}
else{
alert("Your comment is too short, please write more.");
return false;
}
}
code in the form field would be: onsubmit="return checkLength();">
And the text area in the form itself:
<label for="comment">*Comment:</label>
<textarea name="comment" id="comment" rows="4" cols="40" required="required"></textarea>
hope this helps!
<input name="myTextInput" type="text" minlength="5" maxlength="10"></input>
This would do the trick if you do not want to trouble with js.
I have a photography site driven in part by the 'Photoshelter' service, and I put an embedded search bar in my nav.
<form action="http://brettcole.photoshelter.com/search" method="get">
<input type="text" placeholder="search library" size="15" name="I_DSC">
<input type="submit" value="go">
<input type="hidden" name="I_DSC_AND" value="t">
<input type="hidden" name="_ACT" value="search">
</form>
It allows for a search to be executed with the no search term present, which then returns all 12,000 photos in my archive. Is there a best practice for preventing this, such that the user has to type something or nothing will happen when they click search?
It's also present on my advanced search page. This is generated by a search widget shortcode in the Photoshelter back end. I'd like to apply the same thing here, but not sure how the widgetization of it might affect the process.
Many thanks
You can use the onsubmit attribute of the form element to check if the user has entered information in any fields and then prevent submit based on that.
<script>
function checkValues() {
searchBox = document.getElementById("SearchField");
return searchBox.value != ""; // True will allow submission and false will prevent it
}
</script>
With this...
<form onsubmit="checkValues();" action="http://brettcole.photoshelter.com/search" method="get">
<input type="text" id="SearchField" placeholder="search library" size="15" name="I_DSC">
<input type="submit" value="go">
<input type="hidden" name="I_DSC_AND" value="t">
<input type="hidden" name="_ACT" value="search">
</form>
Should do what you need.
See also this answer: How to grab the onSubmit event for a form?
The actual search isn't working
From the contact page for example, it returns this
http://brettcolephotography.com/contact.html?I_DSC=red&I_DSC_AND=t&_ACT=search
the formula for my search returns is
http://brettcole.photoshelter.com/search?I_DSC=red&I_DSC_AND=t&_ACT=search
this search bar is present on all three of my web properties, personal site, blog, and photoshelter site, all three are tightly integrated to where you can't tell when you're switching between them. It needs to work regardless of where the search is being executed from. Thanks
Here is a function I wrote to disable the search form submitting if the search field is empty. It also focuses the cursor on the search field if the form is not submitted so that the user does not think that search is broken.
This is assuming that jQuery is loaded. Hope this helps!
var preventSearchIfEmpty = function() {
$('form[method="get"]').on( 'submit', function( ev ){
var query = $('input[type="text"]').val(),
queryLength = query.length;
if ( 0 === queryLength ) {
// Make the cursor blink so user is aware it's not broken, they need input to search
$('input[type="search"]').focus();
ev.preventDefault();
return;
}
});
}();