I have a JSP web application, i use JavaScript to read a value from a saved cookie, let's say it is a login page and if i found the user name and password in the cookie will automatically add the values in the user name and password in their relative HTML input fields so far i can do this easily, however i need to automatically submit the form without clicking on the submit button, how can i fire this click event wither using JavaScript or JSP?
Note: because of very specific business need and using of third party code and architecture i have to implement the scenario as i described, unfortunately can't use servlets or redirect to other pages
am using the following code, which does not work :(
<%!
//JSP code to validate the cookie and get the values
if(true)
{
%>
<!-- JavaScript code -->
<script type="text/JavaScript">
document.forms["myForm"]["buttonSubmit"].click();
</script>
<%!
}
%>
Related
I think i have searched already about tags and yes i am using them already.
But here my question or Idea is:
I have a form including input to search/insert data into database (mysql) (index.php)
form action is being performed on search.php
search box searches input data in the selected tables, if it is found, then it gives the records in result.php, otherwise it inserts the data in table(sql) and then shows it in result.php
I am validating the form/input using javascript on the same page even using tags
Now after loading the index.php page, if someone disable javascript, it shows an alert to reload the page. if someone reload the page, searchbox will hide.
but the problem is, if after loading the page, if someone disable javascript and does not reload the page, and search some restricted text using javascript regex, that text goes into mysql database and it is saved. search.php perform its action and redirect it to result.php
I want some trick in search.php that checks some condition for javascript enabled/disabled, then perform the remaining actions.
IS THERE ANY WAY, IF ACTION SHOULD BE ANOTHER PAGE, on that page is javascript is disabled then it shows nothing, and if it is enabled then redirects to search.php
Form validation on JS level is unimportant, what you need to think about is your php validation. Please read top answers of: form validation with javascript vs php
and this:
How can I prevent SQL injection in PHP?
If you need to check if JS is enabled you can simply make button for your form (but not type="submit" but just a button element). Add event to that button:
onclick="document.getElementById('FormId').submit();"
and your form will be submitted only if JS is enabled as button will use JS for submission
Use a hidden input field and set its value using javascript on form submission. Since the value will be set only using javascript, if the submitted form has an empty value for this field, it can be concluded that javascript was disabled.
Using jQuery:
In the html:
<form id="myformid" action="myactionurl.php" method="POST">
<!-- form fields here -->
<input type="hidden" id="time" name="time" value="">
</form>
In js:
$('#myformid').submit(function(ev) {
$('#time').val($.now());
});
In php:
if(!empty($_POST['time'])) {
//code
} else {
echo "Javascript must be enabled for this site to work.";
}
You don't have to use time, it can be anything.
I am currently trying to solve a problem on my Wordpress website. I do not have any code just yet (as I have re-written 4 different forms before I gave up), so I will just state what I want to do, I am pretty sure it's quite simple and I'm just missing something.
I need to build a form on the front-end that works like this: user inputs some value, chooses some other value from dropdown, than clicks on the submit button, page does NOT reload, instead a value is calculated and shown (I know how to show a value after click using jQuery), BUT the value that will be shown is calculated using not only form inputs and hardcoded variables, but also Wordpress custom field values using PHP function get_field().
The problem is that if I use ajax to get values from the form without reloading the page, those values are in javascript and I need to use them with PHP get_field() function.
So, to repeat what I intend to do, so It's easier to understand more quickly:
Form where user inputs some values
User clicks submit
The page does not reload
New value is calculated based on user input and custom field value (using get_field())
New DIV is shown using JQuery on submit click (I know how to do this one, but its important because this is the reason why the page must not be reloaded).
If you could just point me in the right direction, I will be able to code everything else.
Why not just inject the custom fields inside javascript variables when building the page template in php? Then you would have all the data available in javascript when the page loads. Something like this:
<?php
echo '
<script type="text/javascript">
var custom_field_1 = '.json_encode(get_field('custom_field_1')).';
var custom_field_2 = '.json_encode(get_field('custom_field_2')).';
</script>
';
?>
On a web server (not mine) with JavaScript pages (probably generated with a Java API) there is a page accessible with authentication. On this page there is a form that I can access with a Perl script and fill input fields, but the validation button of this form, when clicked, open a new window with two buttons. I want my script to click on (validate/cancel) in this new window but I don't know on to access the form. This page contains the HTML code below.
Could you give me hint to access the hidden form?
<div class="button_send_message">
<a class="button" href="#" id="_PRE__MAI:_viewRoot:mainInclude:web2SmsForm:web2SmsSendButton"
name="_PRE__MAI:_viewRoot:mainInclude:web2SmsForm:web2SmsSendButton"
onclick="A4J.AJAX.Submit('_PRE__MAI:_viewRoot:a4jRegion_MessagingPage','_PRE__MAI:_viewRoot:mainInclude:web2SmsForm',
event,{'similarityGroupingId':'_PRE__MAI:_viewRoot:mainInclude:web2SmsForm:web2SmsSendButton',
'parameters':{'org.ajax4jsf.portlet.NAMESPACE':'PRE__MAI','javax.faces.portletbridge.STATE_ID':'d3090bfc\x2D223e\x2D40d3\x2Daf74\x2D7a17042408e6:view:PRE__MAI','_PRE__MAI:_viewRoot:mainInclude:web2SmsForm:web2SmsSendButton':'_PRE__MAI:_viewRoot:mainInclude:web2SmsForm:web2SmsSendButton'}
,'namespace':'PRE__MAI','actionUrl':'/SlfcrMessagingPortlet/faces/pages/main.xhtml?javax.portlet.faces.DirectLink=true'} );
return false;" onmouseout="className='button'" onmouseover="className='button_hover'" title="Envoyer"></a></div>
Does someone knows how I can call a submit form on the window?
The original URL for the form is at /portal/authsec/portal/Selfcare/Messaging
I was able to finaly use a chrome extension "http Trace" that show me clearly what the POST was like, and then I put it on my perl script and it works.
I would like to perform a search via GET from one website's html form to another ASP.net page's form that's on a different webpage. Is this possible?
I want to do this for this website:
http://www.fasnetdirect.com/kaneprls.asp?Page=home
After inspecting element of the search box that says "Search by keywords*" I get the following html tag:
<input type="text" name="SearchString" size="50">
I will have a GET submit form that will query a string over to that search form "Search by keywords*" and have that submitted. So If you search something on my website, it will enter in the string the user typed in on my website, inject it into that "Search by keywords*" input area then automatically hit "search".
Is this possible to do with either PHP, or JavaScript? and if so, what is this called?
I'm using authorize.net's SIM approach, which needs a normal form to be submitted to their TLS host from the user's browser. The setup is done on my server, I just need to create the form and auto-post it when the page loads.
I want it to be posted from the browser so that the user can then fill in the credit card information on authorize.net's host and process the payments. I don't want any of that credit card stuff on my server.
At this point in the process, there is no data for the user to enter, and no more choices, all that happened before we get to here.
Seems like a bit of jQuery to trigger the submit when onLoad() is done.
Is this the best way to approach the problem?
You don't even need jQuery for this because it is so simple. As soon as the page loads with your form on it you just need it to auto-submit the form you. Placing this code at the bottom of the page will do this for you (assuming the form is named myform):
<script type="text/javascript">
document.myform.submit();
</script>
This can be easily adjusted to use jQuery if you'd like but it should give you the right idea.