passing javascript value into form action - javascript

I have the form:
<form name="form1" method="post" action="test.php?date=javascript:this.form.date2.value">
I am using a DatetimePicker for PHP like below:
$myCalendar = new tc_calendar("date2");
$myCalendar->setIcon("calendar/images/iconCalendar.gif");
$myCalendar->setDate(date('d'), date('m'), date('Y'));
$myCalendar->setPath("calendar/");
$myCalendar->setYearInterval(1970, 2020);
$myCalendar->dateAllow('2008-05-13', '2015-03-01', false);
$myCalendar->startMonday(true);
$myCalendar->autoSubmit(true, "form1", "test.php");
$myCalendar->autoSubmit(true, "form1");
$myCalendar->showWeeks(true);
$myCalendar->writeScript();
The thing is i cannot pass the date value from datetimepicker into form action where the url is "test.php?=date="
How would this be possible to pass the value of datetimepicker by just clicking on calendar, not using any extra button and using onsubmit event.
After execution the result in URL looks like this:
test.php?date=javascript:this.form.date2.value
Thanks

You should not need javascript to submit a form without ajax.
As you want to sent GET variables with ? sign, jsut use GET method in your form and set the name of the input to the name of the variable you want to get sent. (if you can replace 'date2' with 'date'):
<form name="form1" method="get" action="test.php">
<input name='date' />

Related

jquery the parameter passed in is null when set form action attribute

I am trying to set my form action to another page with a parameter in url using code below:
ui.setFormActionToTargetPage = function () {
$('form').get(0).setAttribute('action', 'myTargetPage.html?id='+id);
};
My html page is like
<form class="form-horizontal row-border" data-validate="parsley" id="validate-form" enctype="multipart/form-data">
...
<button class="btn-default" onclick="ui.setFormActionToTargetPage();">Cancel</button>
...
</form>
However, I did get forwarded to myTargetPage.html but it seems the id parameter is not passed while some form content was passed as parameter 'text'. I verified that when setFormActionToTargetPage is called the url is as expected. However, when it hit the target page, the window.location.href is not correct, which is 'myTargetPage.html?text= some form content'. Anyone know why?
Thanks.
Change the form method to post so the form data doesn't interfere with the querystring. If you have your id value somewhere and it's working already then great, otherwise you can pass it through the button onclick call like this.
<form method="post" class="form-horizontal row-border" data-validate="parsley" id="validate-form" enctype="multipart/form-data">
<button class="btn-default" onclick="ui.setFormActionToTargetPage(123);">Cancel</button>
</form>
ui.setFormActionToTargetPage = function (id) {
$('form').prop('action', 'myTargetPage.html?id='+id);
};

set value in a form or pass a value in a form using jquery or javascript or ajax

i created a Google Form and list down all the ID in each input type, and then created a localhost with the same ID,
The first thing i want to do is to save the values into a localhost and pass the values in the Google Form or set the values into the corresponding ID or Name in each input type in a new tab, is there a way to do this using ajax or jquery?
my form looks like this
<form method="post" action"">
<input type="text" name="FName">
<input type="text" name="LName">
<input type="Submit">
</form>
$post('https://docs.google.com/a/grabtaxi.com/forms/d/e/1FAIpQLSfjiuhFbURVavdNW82ofHG3gPpBUKkK2VATQQKmV-YKKrJ75Q/viewform'{FName:Fname,LName}function(){
window.open('https://docs.google.com/a/grabtaxi.com/forms/d/e/1FAIpQLSfjiuhFbURVavdNW82ofHG3gPpBUKkK2VATQQKmV-YKKrJ75Q/viewform');
});
i am trying to use the $.post() in jquery but it looks like i cannot set the values into the Google Form.
Any tips please... Thank You very much
You should wrap your javascript code inside a scipt tag. Then, you should bind the code to submit event, tha happened when you press the submit button.
<script type="JavaScript">
$('input[type=submit]').submit(
// here you should put your code
});
</script>
And check your code, you wrote $post instead of $.post mi sing the dot.

confusing syntax in JSP portal

JSP code in Liferay portal..
<portlet:actionURL name="addDetails" var="addDetailsURL" />
where from var gets value ?
var just exposes the action URL value through a variable named addDetailsURL. This is so that you can use it conveniently in a link as so:
Link
is used to perform any action(Action Phase) i.e user submitting form and controller(processAction) processes that request.
i.e
<form action="<%= addDetailsURL %>" method="POST" name="form">
// input fields which will get submitted to controller
</form>
from pageContext.
ActionURL.toString() is assigned to addDetailsURL and added to pageContext

Javascript Submit Back to Form

I am building a search by city function. Once you have typed in the search field, and if there are multiple cities, you are then presented with all the options.
Each option is a link with javascript, which when clicked should input the value (zipcode) back into the form for processing. The error I am getting is this:
Uncaught TypeError: Cannot call method 'submit' of undefined
Here is my javascript (yep Im using smarty):
{$row.City}, {$row.State} {$row.Zipcode}
Here is my form:
<form action="mymethod.php" method="POST" id="myform">
As you can see I am trying to pass the zipcode back to the form for processing upon 'click'
Appreciate any insight anyone cares to share
The document.forms collection has named elements, which refer to <form> elements with a corresponding name attribute.
To refer to your form, add name="myForm".
<form action="mymethod.php" method="POST" name="myform">
Instead of using a link, I strongly recommend to use a <input type="submit"> element, to not drive away users who have disabled JavsScript.
onclick="javascript:$('#myform').submit({$row.Zipcode}); return false"
Name you form instead: <form action="mymethod.php" method="POST" name="myform">
Then call it using: document.forms["myform"]

jQuery form action change

Normally to change the action attribute of a form in jQuery I would do the following:
<form id="removeLightboxForm" action="">
...
</form>
$('#removeLightboxForm').attr("action", "view/#close");
But I usually use this for when the action attribute is empty on the HTML form tag itself. I'm now trying to use this on a form where the action attribute already contains a default URL and is causing problems.
In this example, the form action is present:
<form id="removeLightboxForm" action="view/">
...
</form>
But when I do this:
$('#removeLightboxForm').attr("action", "view/#close");
I end up with the new URL/action being added to the original URL/action, for example:
<form action="view/view/#close" ...
Is this how it's supposed to work or am I doing something wrong?
I would try clearing it first:
$('#removeLightboxForm').attr("action", "").attr("action", "view/#close");
or
$('#removeLightboxForm').removeAttr("action").attr("action", "view/#close");

Categories

Resources