Javascript Submit Back to Form - javascript

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"]

Related

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.

JavaScript submit not working for action on same page

I'm just trying to submit my form using JavaScript. I've broken it down into this basic function:
$(btnSubmit).click(function(event){
event.preventDefault();
$('.form')[0].submit();
});
This is the form (the page name is upcoming_albums.php):
<form class="form" action="upcoming_albums.php" enctype="multipart/form-data" method="post">
All it does is refresh the page. The form does not get submitted.
I think there is a problem with your selector, For submitting form using JavaScript it best practice to use the form name or the unique ID, because there maybe a same class name used other places.
So, try the following code,
<form class="form" id="myform" action="upcoming_albums.php" enctype="multipart/form-data" method="post">
Now, javascript will be something like
$(btnSubmit).click(function(event){
event.preventDefault();
$('#myform').submit();
});
Also please check your console for any other js error, this might help,
Thanks,

html Form not recognized in my jsp page

I have a JSP page which is included in the main page..Within the JSP page, I have given a HTMLform which I want to submit() once the user clicks it using Jquery?
<form id="orderBean1" name="myForm" action="/Auto/Item" method="post">
<input id="filename" name="filename" value="" />
</form>
First,
Suprisingly, this form is not recognized within the page..
When I give $('#orderBean1') in my console it does not give the form object whereas $('#filename') gives me the filename input element.
Second ,
As the form is not recognized it does not get submitted...
$("#vehreport").click(function(e) {
e.preventDefault();(I have given this stmt even after the submit() and still not working...
$("#orderBean1").submit();
alert("formsubmnittted");
})
Question -
Why doesn't the form element is recognized in my page?
I set up a JSbin here.
As you can see, #orderbean1 is recognized, and submits.
The error is likely elsewhere is your JS or markup, though if I'm misunderstanding the question please clarify

passing javascript value into form action

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' />

How do I use Javascript to force cursor to specific form field when form field has a name with brackets?

I am using CakePHP as my framework.
On page load, I want to force the cursor to a specific form field where name="data[Project][title]"
I'm trying to use javascript:
This works fine if I change the name to something without brackets, but fails to work with this form name. I have to use this form field name because of how CakePHP processes my form data.
Is there a workaround or another simple way to force the cursor to this form field?
Here is the code I currently have (if you change "data[Project][title]" to "formField" it works):
<body onLoad="document.searchForm.data[Project][title].focus();">
<form action="http://beta.industrialinterface.com/users/mainadd/" method="post" id="create-form" name="searchForm">
<input id="main-input" type="text" class="title-limit" name="data[Project][title]" onClick="this.value='';limitText(60);" onKeyDown="limitText(60);return true;" onKeyUp="limitText(60);return true;" />
Example code? Because otherwise you could simply do:
document.getElementById('id_for_your_input').focus();
If you are using a form and have access to the form element you can do
formelement['data[project][title]'].focus();
example at http://www.jsfiddle.net/fqgxv/
You can use getElementsByName() for this. Note that it returns an array.
Ex:
<body onLoad="document.getElementsByName("data[Project][title]")[0].focus();">

Categories

Resources