I have a page with a live search function called "list.php". On another page, I have a search input, and upon submit of that search, I'd like to take the query, load list.php and fill the live search on list.php.
list.php has the following:
<input type="text" id="myInput" onkeyup="databaseSearch()" placeholder="Search">
And my other page's search is:
<form action="search2.php">
<input class="mb0" type="text" placeholder="Search..." />
</form>
I would think the best way to do this would be with a form action, but I'm not sure how to both load list.php AND fill in #myInput
Thanks!
Passing Value in the Function would get the text typed through, and using .val() means you wish to put the value gotten into any form field required there is value="" option
This is a script pointing to Jquery CDN file online
<script src="https://code.jquery.com/jquery-3.3.1.js" integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60=" crossorigin="anonymous"></script>
If you have Jquery You Prolly won't need this
<script src="https://code.jquery.com/jquery-3.3.1.js" integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60=" crossorigin="anonymous"></script>
<input type="text" id="myInput" onkeyup="databaseSearch(value)" placeholder="Search">
<form action="search2.php">
<input class="mb0" type="text" placeholder="Search..." />
</form>
<script type="text/javascript">
function databaseSearch(value) {
$(".mb0").val(value);
}
</script>
Important Additions are
onkeyup="databaseSearch(value)"
And
function databaseSearch(value) {
$(".mb0").val(value);
}
Good Luck :)
do something like that and change what suites your script, also do not forget using proper filters :
this on list.php and make the other form action points to list.php too:
<?php
if(isset($_POST['another_page_txt'])): ?>
<script>
$('#myInput').val('<?php print $_POST['another_page_txt']?>');
$('#myInput').trigger('keyup');
</script>
<?php endif;?>
Related
I have a javascript snippet:
<script language="JavaScript" type="text/javascript" src="/partner/display.php?token=id"></script>
It's from the affiliate program we use, iDevaffiliate.
When included in the html of a page, it reads a value (the affiliate id) to the page, so the visitor can see it.
I need to get this same value inserted into to a hidden form field such as:
<input type="hidden" name="affid" id="affid"" value="value goes here">
This will allow us to submit the affiliate id in the form as a hidden value.
Any suggestion on how to include the value outputed by the javascript snippet as a value into the hidden form field?
The script itself doesn't work as a value in the form, atleast when I tried it in different ways. Thanks for any help.
Here is example page with js in the page, and a sample form. The value -100 should be created and visible when viewing the page (from the js): http://www.lifeleap.org/100-1-3-19.html
After Help and More Research, This Is What I Have So Far:
Script prints value here: <div id="affjs"><script language="JavaScript" type="text/javascript" src="/partner/display.php?token=id"></script></div>
<script type="text/javascript">
$('#testform').submit(function () {
var outputValue=document.getElementById("affjs").innerHTML;
document.getElementById("aff").value=outputValue;
});
</script>
<form method="post" action="/scripttest3.php" id="testform">
<input type="hidden" name="aff" id="aff" value="">
<button type="submit" value="Submit">Submit</button>
</form>
It's not finished, but I think I'm on the right track. Maybe onsubmit script needs to be included inside form? Thanks for any suggestions.
You will need to find the value in the DOM and then store in your hidden input field.
var outputValue=document.getElementById("id-of-html-tag-where-output-value-is").innerHTML;
document.getElementById("id-of-hidden-input-field").value=outputValue;
You should do this on form submit.
Inside the Javascript you can use like this
document.getElementById("affid").value ='value goes here' ;
I have a java script function that i need to call over and over again in order to test it, so i wrote a form that allows me to call the function, i have to do this manually and need a way to call this function without user input. all that needs to go to the upload file is a number and some text, (ex 1 Thank you)
<script src="yo.js"></script>
<!DOCTYPE html>
<html>
<body>
<form action="uploadFile" method="post">
<input type="text" name="filename" >
<input type="text" name="fileData">
<input type="submit">
</form>
</body>
</html>
Runs every second:
setInterval(function () {uploadFile('some text', 'some number')}, 1000);
I have a form with several different text inputs. The value of each corresponds to a unique JavaScript variable. The variable is then written out on the page.
Is there a way to update the variable automatically so the user doesn't have to hit submit and reload the page each time? I have heard AJAX could be a potential answer to this, but I am unfamiliar with it. If that route is best, are there certain scripts that would be recommended?
You might want to look into jQuery as a good first start into javscript in the browser. For instance, you could write:
<form id="form-id">
<input id="first" type="text" />
<input id="second" type="text" />
<input id="third" type="text" />
</form>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script>
var first, second, third;
$(function(){
$("#form-id").submit(function(){
first = $("#first").value();
second = $("#second").value();
third = $("#third").value();
return false; //Prevent the form from submitting.
});
});
</script>
http://jquery.com/
I'm not hugely good with javascript or jQuery, mainly dealing with databases, but I've been having a little trouble getting a rather complex form to submit all its data.
Basically it amounts to three different submit buttons which are meant to post the data in the form with a different privacy setting sent to the table. The table in the database is being updated with the correct privacy setting for each button, but it isn't sending a value for the thought part of the form to the php file it is meant to.
The form is implemented in the HTML as follows:
<FORM action="thought_post.php" method="post" name="thought">
<INPUT onfocus="this.select(); this.value=''"
type="text" value="Thought..."
size="72" />
<div class="megamenu" style="position: absolute; ;left: 478px; top: 11px;">
<ul>
<li class="downservices">Publish...</li>
<div class="servicesdropped">
<ul class="right">
<input type="hidden" name="privacy">
<li>Private</li>
<li>Friends only</li>
<li>Public</li>
</ul>
</div>
</ul>
</div>
</FORM>
and the javascript in the header of the same page is as follows:
<link rel="stylesheet" href="dropdown.css" type="text/css" media="screen" />
<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".downservices").click(function(){
$(".servicesdropped").toggle("fast");
});
});
</script>
<script language="JavaScript" type="text/javascript">
<!--
function poststyle(selectedtype)
{
document.thought.privacy.value = selectedtype ;
document.thought.submit() ;
}
-->
</script>
If anyone could explain why the thought value entered by the user isn't being passed to thought_post.php that would be wonderful!
Try assigning a name to your "thought" input. name is required for a form control to be valid for submission:
<INPUT onfocus="this.select(); this.value=''" type="text" value="Thought..." size="72" name="thought" />
As a side note, make sure your other input is valid markup as well, input tags should be self closing:
<input type="hidden" name="privacy" />
After making these changes and inspecting the form post with FireBug, I could see the correct value for "thought" go through.
Additionally, as the other answer mentions, you should separate your JavaScript and HTML and maybe accomplish this completely with jQuery.
Hope that helps!
Try setting an id for the privacy field (like, say, id="privacy") and selecting it with this:
getElementById("privacy").value = selectedtype;
By the way, you can put all the javascript in one <script> block:
<script type="text/javascript">
$(document).ready(function(){
$(".downservices").click(function(){
$(".servicesdropped").toggle("fast");
});
});
function poststyle(selectedtype)
{
document.thought.privacy.value = selectedtype ;
document.thought.submit() ;
}
</script>
You could also very easily handle the focus event on your input with jQuery so the scripting isn't down in your HTML.
I have to place a link to a webpage through an <a> .The webpage link contains some request parameters and I don't want to send it across through the browser directly (meaning I want to use something similar to POST method of FORM).
<a href="www.abc.do?a=0&b=1&c=1>abc</a>
I am using this inside a jsp page and is there a way to post it through javascript or any other way where I don't pass the request parameters through the url?
You can use links to submit hidden forms, if that's what you're asking.
Click Me
<form id="secretData" method="post" action="foo.php" style="display:none">
<input type="hidden" name="foo" value="bar" />
</form>
<script type="text/javascript">
function submitForm(formID) {
document.getElementById(formID).submit();
}
</script>
Use the form tag with hidden fields to submit your data:
GO !!
<form name="frm" action="www.abc.do" method="post">
<input type="hidden" value="your-data" name="whatever">
<input type="hidden" value="your-data" name="whatever">
<input type="hidden" value="your-data" name="whatever">
</form>
You can use AJAX for that. For example, with jQuery, you can use the post function:
clickMe
<script type="text/javascript">
$(function(){
$("#myMagicLink").click(function(){
$.post("www.abc.do", {"a":0, "b":1, "c":1});
});
});