JavaScript - Change Form And Action And Then Auto Submit Question
Hi, I have a body onload doing multiple things, changing a select option value, changing the form submit action and then auto submitting.
Everything works fine until the auto submit part of it. Code: function run() { document.myform.myselect.selectedIndex = 1; document.myform.action = 'page.php?x=1&y=2'; document.myform.submit(); } <body onload="run()"> Thanks for any help with this Similar TutorialsHere is the code for test.html: Code: <html> <head><title></title></head> <body> <script type="text/javascript"> function OnSubmitForm(){ document.myform.action ="insert.html"; return true; } </script> <form name="myform" onsubmit="return OnSubmitForm()" method="get"> <input type='radio' name='Search' value='test'>test</input> </form> <a href='javascript:document.myform.submit()'><img src='images/buttonnext.jpg'></a> </body> </html> The way I want it to work: when the img (buttonnext.jpg) is clicked, the form is submitted. When the form is submitted it runs the javascript, which sets the action to be that insert.html is loaded. i.e. the end result should be to redirect to insert.html?Search=test The way that it is working now: the page is redirected to test.html?Search=test Note: If I use a submit button that is part of the form (i.e. input field with type "submit") the page is redirected correctly. What do I need to change to accomplish my goal? hi, Can any one tell how to change action attribute in form tag using javascript. thanks in advance regards sugeet Ok - I'm using an 'off the peg' shopping cart (Mal's e-commerce) that posts items to the cart using a standard form with a submit button. What I want to do is send an item to the cart 'automatically', that is without the user actually filling a form or pressing a 'submit' button. What I send to the cart will be dependant upon the value of a cookie that will have been set at some earlier point in the session. My plan was to use document.write statements to build the 'form' and send it to the shopping cart... Here is the kind of form i will be creating: <form method="post" /> <input type="hidden" name="product" value="XXXXXXXX" /> <input type="hidden" name="price" value="0.00" /> <input type="hidden" name="qty" value="1" /> <input type="submit" value="add to basket" /> </form> 1) 1st problem the product value "XXXXXXXX" actually needs to be 'constructed' out of text plus the value held in the cookie eg... 'here is your COOKIEVALUE product' what i was going to try here was "here is your" + COOKIEVALUE + "product" which doesn't work - but that's what I'm trying to achieve. 2) 2nd problem is the submit 'button' needs to be an automatic 'invisible' action - i don't actually want to give them a button to click i just want to submit it from the coding. Hope that makes some kind of sense! OK so I have a variable called url and I want to move its contents into the form action once the button is submitted. <script type="text/javascript"> function elibrarySearchGo(){ var url = "http://url'" } </script> <form name="searchform" target="_blank" action="" onsubmit=""> I need the syntax as to how to put in a variable coming from javascript inside onsubmit="document.form.action.value = variable" for example. Also, is it better to run this population of the action onsubmit or onclick? Thanks all in advance!! Hi i have a form inside a frame, for example: <html> PHP Code: <body> <div><h1>Header</h1><hr /></div> <iframe height="75%" width="75%" src="iframe.php" frameborder="0"> Iframe should be enabled. </iframe> <div><hr /><h1>Footer</h1></div> </body></html> in iframe.php PHP Code: <form action="http://some-url" id="my_form" name="my_form" method="POST"> <!-- hidden fields goes here ---> <input id="<?php echo $key; ?>" name="<?php echo $key; ?>" value="<?php echo $value; ?>" type="hidden"/> <!-- //hidden fields goes here ---> </form> <script type="text/javascript">document.getElementById("my_form").submit();</script> I would like to know how to submit the iframe.php form so that it goes out of frame. I think we need to tweak this code: PHP Code: <script type="text/javascript">document.getElementById("my_form").submit();</script> Thanks in advance. I am trying to write a javascript page where the primary form of user input is an HTML form (shown below) Code: <form id=UI> State: <input type="text" name="state" > Postal abriviation: <input type="text" name="ab"> Capital: <input type="text" name="cap"> <input type="button" name="answer" value="Answer" onClick="check()"> <br> <input type="button" name="show_name" value="Show State" onClick="hint=1;select_state();"> <br> <input type="button" name="show_ab" value="Show Abriviation" onClick="hint=2;select_state();"> <br> <input type="button" name="show_cap" value="Show Capitol" onClick="hint=3;select_state();"> </form> the button named 'answer' does what i want, but when the user pushes enter, if he is in one of the form fields it automatically sends him to the url with all of the form date (www.url.com?state=maryland&ab=md&cap=annapolis) i modified my body tag to run the 'check()' function when enter is pushed, which it does but immideatly sends me to the following url Code: <body onload="first_run()" onkeydown="if (event.keyCode == 13){check()}"> is their any way to disable to the submit built into the form tag either through HTML or javascript? My html form code is <html> <head> <script type="text/javascript" src="2.js"></script> </head> <body> <h1 id="remain"></h1> <form action="3.php" method="post" id="form1" name="form1"> <input type="text" name="id"> <input type="submit" name="submit" value="submit"> </form> </body> </html> I need to submit the form after coundown.Here is my countdown script file window.onload=counter; function counter() { var seconds = 5; countDown(); function countDown() { document.getElementById("remain").innerHTML=seconds; if(seconds>0) { seconds=seconds - 1; setTimeout(countDown,1000); } if(seconds == 0) { document.form1.submit(); } } } Countdown is working but form does not submit after countdown.Please help me regarding this.Thanks in advance he everyone please i want to know how to submit a form using ajax every 5 minutes without reloading page i have a huge form for exams and i need to submit the form without the need to wait until pressing submit because the user may wait to think about the answer a very long time.. so i want to submit the form and at the same time i cant reload the page as it is in normal submit form.. so how i can submit form in the background without letting the user knows that the form is submitted??? Hello I need help to simulate a click /start action on a SWF button element without clicking it.. so when i access the form the auto action will take place Would be awsome if someone can help me Code: <html class="no-js" lang="en" xmlns:og="http://opengraphprotocol.org/schema/" xmlns:fb="http://www.facebook.com/2008/fbml"> <!--<![endif]--> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <script src="http://www.google.com/jsapi?key=ABQIAAAAAJ5I0tmbz-jcO3Ja4fwvEBTb9u7IFi28hLXI-qXjI6UBBcarTBQ49g-wp7Wxnow1_w9F-7_GcOOnyg"></script> <script> google.load("jquery", "1.7.0"); google.load("swfobject", "2.2"); </script> </head> <body> <div id="container"> <div id="main" role="main"> <div id="data" class="channel"> <div id="openbutton"> <div id="flashcontent1";></div> <!-- DR1 Start --><script> params = {}; params.text = 'DR1'; params.action = "channel"; params.value = "40"; swfobject.embedSWF('content/linkbutton.swf', 'flashcontent1', '145', '30', '9.0.115', 'content/expressinstall.swf', params, {allowFullscreen:'true', wmode: 'transparent' ,bgcolor: '#FFFFFF', menu: 'false'}, {id: 'flashcontent1'}); <!-- DR1 Ends --></script> </div></div></div> </div></body></html> Hello everyone, I have a webpage with three different search options. Each option has a radio button clicking on which enables the text fields and buttons in that option with the help of java script. The first options allows to search by PIN. Second one by SSN, DOB and DOBRange, And 3rd one by various combinations of the name. The javascript I use to do this is given below: Code: function chMd() { // initialize form with empty field document.forms[0].PIN.disabled=false; document.forms[0].PIN.value=""; document.forms[0].SSNfirst.disabled=false; document.forms[0].DOBRange1.disabled=false; document.forms[0].DOBRange1.value=""; document.forms[0].DOBRange2.disabled=false; document.forms[0].DOBRange2.value=""; document.forms[0].LastName.disabled=false; document.forms[0].LastName.value=""; document.forms[0].FirstName.disabled=false; document.forms[0].FirstName.value=""; document.forms[0].MiddleName.disabled=false; document.forms[0].MiddleName.value=""; document.forms[0].Last4.disabled=false; document.forms[0].Last4.value=""; document.forms[0].First4.disabled=false; document.forms[0].First4.value=""; document.forms[0].DOB1.disabled=false; document.forms[0].DOB2.disabled=false; document.forms[0].Option1.disabled=false; document.forms[0].Option2.disabled=false; document.forms[0].Option3.disabled=false; for(var i=0;i<document.forms[0].elements.length;i++) { if(document.forms[0].elements[i].name=="dOption") { if(document.forms[0].elements[i].value=="N") { if(document.forms[0].elements[i].checked==true){ document.forms[0].PIN.disabled=false; document.forms[0].SSNfirst.disabled=true; document.forms[0].DOB1.disabled=true; document.forms[0].DOBRange1.disabled=true; document.forms[0].DOB2.disabled=true; document.forms[0].DOBRange2.disabled=true; document.forms[0].LastName.disabled=true; document.forms[0].FirstName.disabled=true; document.forms[0].MiddleName.disabled=true; document.forms[0].Last4.disabled=true; document.forms[0].First4.disabled=true; document.forms[0].Option1.disabled=false; document.forms[0].Option2.disabled=true; document.forms[0].Option3.disabled=true; } } else if(document.forms[0].elements[i].value=="T") { if(document.forms[0].elements[i].checked==true){ document.forms[0].PIN.disabled=true; document.forms[0].SSNfirst.disabled=false; document.forms[0].Last4.disabled=false; document.forms[0].DOB1.disabled=false; document.forms[0].DOBRange1.disabled=false; document.forms[0].DOB2.disabled=true; document.forms[0].DOBRange2.disabled=true; document.forms[0].LastName.disabled=true; document.forms[0].FirstName.disabled=true; document.forms[0].MiddleName.disabled=true; document.forms[0].First4.disabled=true; document.forms[0].Option1.disabled=true; document.forms[0].Option2.disabled=false; document.forms[0].Option3.disabled=true; } } else if(document.forms[0].elements[i].value=="R") { if(document.forms[0].elements[i].checked==true){ document.forms[0].PIN.disabled=true; document.forms[0].SSNfirst.disabled=true; document.forms[0].Last4.disabled=true; document.forms[0].DOB1.disabled=true; document.forms[0].DOBRange1.disabled=true; document.forms[0].DOB2.disabled=false; document.forms[0].DOBRange2.disabled=false; document.forms[0].LastName.disabled=false; document.forms[0].FirstName.disabled=false; document.forms[0].MiddleName.disabled=false; document.forms[0].First4.disabled=false; document.forms[0].Option1.disabled=true; document.forms[0].Option2.disabled=true; document.forms[0].Option3.disabled=false; } } } } } This works fine but the problem is we have 3 submit buttons with differnt actions using the normal <s:submit> works fine but when I use <s:submit action="Search1"> the javascript does not render. Here is an example of my jsp code: Code: <s:form id="Search" name="units" action="Search1"> .... ... <Table> <tr><td> <input name="dOption" value="T" onClick="chMd()" type="radio"> Option 2 <br /></td></tr> <tr> <td> <s:textfield name="crssn" label="SSN:" size="9" maxlength="9" disabled="true" value="xxxxxxxxx" onclick="clearText(this);"onblur="clearText(this);" required="true"/></td> <td><br><s:checkbox name="last4" label="Last 4" labelposition="bottom" disabled="true"/></td></tr> <tr><td><s:textfield label="DOB:" name="crdob1" size="10" maxlength="10" disabled="true" value="mm/dd/yyyy" onclick="clearText(this);"onblur="clearText(this);" /></td> <td><s:textfield name="crrange1" label="+/- months" size="1" disabled="true" /></td><td> </td><td> </td> <td> <s:submit action="Search2" name="Option2" value="Search"/></td></tr> </Table> Similarly for the other options. This does not seem to work. However if I use the same code without specifying an action it works. e.g. Code: <Table> <tr><td> <input name="dOption" value="T" onClick="chMd()" type="radio"> Option 2 <br /></td></tr> <tr> <td> <s:textfield name="crssn" label="SSN:" size="9" maxlength="9" disabled="true" value="xxxxxxxxx" onclick="clearText(this);"onblur="clearText(this);" required="true"/></td> <td><br><s:checkbox name="last4" label="Last 4" labelposition="bottom" disabled="true"/></td></tr> <tr><td><s:textfield label="DOB:" name="crdob1" size="10" maxlength="10" disabled="true" value="mm/dd/yyyy" onclick="clearText(this);"onblur="clearText(this);" /></td> <td><s:textfield name="crrange1" label="+/- months" size="1" disabled="true" /></td><td> </td><td> </td> <td> <s:submit name="Option2" value="Search"/></td></tr> </Table> Code: <Table> <tr><td> <input name="dOption" value="T" onClick="chMd()" type="radio"> Option 2 <br /></td></tr> <tr> <td> <s:textfield name="crssn" label="SSN:" size="9" maxlength="9" disabled="true" value="xxxxxxxxx" onclick="clearText(this);"onblur="clearText(this);" required="true"/></td> <td><br><s:checkbox name="last4" label="Last 4" labelposition="bottom" disabled="true"/></td></tr> <tr><td><s:textfield label="DOB:" name="crdob1" size="10" maxlength="10" disabled="true" value="mm/dd/yyyy" onclick="clearText(this);"onblur="clearText(this);" /></td> <td><s:textfield name="crrange1" label="+/- months" size="1" disabled="true" /></td><td> </td><td> </td> <td> <s:submit action="Search2" name="Option2" value="Search"/></td></tr> </Table> Any idea what I need to change in my javascript or jsp to get this to work? On my site's shopping cart, when clicking the "buy" button, it merely animates a little item that shows that something is now in the customer's cart. I'd like it to do this, and then redirect to "/cart", cutting down the work of what the user actually has to do (we only have one product). Here's what I'm working with: <!-- START ADD TO CART --> {% if featuredproduct.available %} <span class="featured-product price"><span>{{ featuredproduct.price | money }}</span>{% if featuredproduct.compare_at_price_max > featuredproduct.price %} <del>{{ featuredproduct.compare_at_price | money }}</del>{% endif %}</span> <input type="submit" value="{{ settings.text_addtocart }}" class=" add-to-cart addtocart button primary"> {% else %} <h3 class="featured-product price sold-out"><span>Sold Out</span></h3> <input type="submit" value="{{ settings.text_addtocart }}" class="featured-product add-to-cart button primary disabled" disabled="disabled "> {% endif %} <!-- END ADD TO CART --> Adding an "onclick="location.href='/cart';" after the input classes does not fire the actual act of adding the item to the cart, so it shows an empty cart on the redirect. JS newbie, sorry for the rough explanation. Any help greatly appreciated! i need a function that count down until zero. how could i make it auto submit which is very important for me and accepts the choices which are as radio buttons instead of waiting for users to push submit button.
So I have a little calendar widget on my site, for people to choose their dates for a reservation system. They then click a 'Book Now' button which creates a dynamic url (using their start date and the number of dates) to the booking engine. The problem is, the way it accomplishes this (window.location.href=), breaks cross-domain tracking on Google Analytics. And I'm not smart enough to figure out how to do it any other way. What I'd like to do is have clicking the Book Now button change the URL in the form action within the form with ID resForm, and then submit the form. I'm hoping someone can help me edit the form so that it accomplishes this. I'd be incredibly thankful. This is what I currently have: Code: <script> jQuery(document).ready(function($) { $(".book-now").click(function() { if($('#check-in').length > 0 && $('#DepartureDate').val() != '') { var data = $('#check-in').val(); var arr = data.split('/'); var datac = $('#DepartureDate').val(); var arr2 = datac.split('/'); var oneDay = 24*60*60*1000; // hours*minutes*seconds*milliseconds var firstDate = new Date(arr[2],arr[0] -1,arr[1]); var secondDate = new Date(arr2[2],arr2[0] -1,arr2[1]); var diffDays = Math.round((firstDate.getTime() - secondDate.getTime())/(oneDay)); if ((diffDays) < 0) { diffDays = Math.abs(diffDays); var link = "https://res.windsurfercrs.com/bbe/page1.aspx?propertyID=13841&checkin=" + arr[0] + "/" + arr[1] + "/" + arr[2] + "&nights=" + diffDays; console.log(link); window.location.href= link; } else { alert ('Please fill in correct Check-In and Check-Out dates. The Check-In date must be before the Check-Out date.'); } } else { alert ('Please fill in a Check-In and Check-Out date, thanks!'); } }); }); </script> The form looks like this: Code: <form action="#" onSubmit="_gaq.push(['_linkByPost',this]);" method="post" id="resForm"> <input type='text' name="checkin" id="check-in" readonly="readonly" style="cursor: text" data-default="MM/DD/YYYY" class='arrivaldate'/> <input name="checkout" id="DepartureDate" readonly="readonly" style="cursor: text" data-default="MM/DD/YYYY" class='departuredate'/> <input type="button" value="BOOK NOW" class='book-now' /> </form> Reply With Quote 01-25-2015, 12:46 AM #2 Old Pedant View Profile View Forum Posts Supreme Master coder! Join Date Feb 2009 Posts 28,310 Thanks 82 Thanked 4,754 Times in 4,716 Posts Just call the _gaq() function manually. Code: _gaq.push(['_linkByPost',document.getElementBy("resForm")]) window.location.href= link; What needs to be done to have the below input (red) passed to the forms action (blue) when the submit button is pressed. Obviously this should be the user input value and not the default 0.00 one. Ty. echo ' <center> <form method="post" action="https://www.paymate.com/PayMate/ExpressPayment?mid=MoreBloodWine&popup=false&ref=EoJ Market Place Donation¤cy=USD&amt= 1.23 &amt_editable=N&return=http://www.eojmarket.com"> Donation Amount: $<input style="vertical-align: middle; color: #FFFFFF; background-color: transparent; border: 1px solid; border-color: #9E853D; padding: 0px 0px 0px 1px; font-size: 10px; width: 50px;" name="amount" type="text" maxlength="6" value=" 0.00 "> <br /> <input type="image" style="padding-top: 10px; padding-bottom: 10px; border: none;" src="http://www.eojmarket.com/NonForumStuff/images/paymate-donate-button.png" value="Submit" alt="Pay with Paymate Express !"/> </form> </center> '; Hi there, I have found some script to auto change an image on my website, but i would like to do this in 2 other places using completely new pictures. for ease i have set up 3 cells in a table and would like them to appear in each cell. Can any body help altering my code to allow this. The code i have so far is Code: <html lang="en"> <head> <script type="text/javascript"> var c=0 var s function photoGallery() { if (c%4==0){ document.getElementById('photo-gallery').src = "boots.jpg"; } if (c%4==1){ document.getElementById('photo-gallery').src = "adidas.jpg"; } if (c%4==2){ document.getElementById('photo-gallery').src = "play.jpg"; } if (c%4==3){ document.getElementById('photo-gallery').src = "argos.jpg"; } c=c+1 s=setTimeout("photoGallery()",1000) } </script> </head> <body onLoad="photoGallery()"> <table border="1"> <tr> <td><img src="amazon.jpg" id="photo-gallery" width="420" height="260"></td> <td>another image loop here</td> <td>and another image loop here</td> </tr> </table> </body> </html> Thank you in advance I am trying to auto submit a login form remotely using .submit() . It's submitting, but for some reason if I use submit() the login isn't processing. However, if I turn off the auto submit and use an actual submit button it logs in just fine. Now, in the form tag there is a call onsubmit for some validation, does .submit() trigger that form onsubmit="" function? Is there something that happens differently when a user clicks a button verses the .submit(). Thanks! Paul Hi - Im pretty new to all this! Have created a form on my website, uploaded database to server, but when the form is submitted - instead of opening the property selection, it just lists the Index of /home/properties and files within that folder. Can anyone help me please? Perky
Need help adding var target to this form action Would This be correct? var form = inp.form; form.target = "_self"; Code: <html> </head> <script type="text/javascript"> function formop(inp,op) { var form = inp.form; form.action = op + ".php"; var temp = inp.id.split(","); form.id.value = temp[0]; form.FirstName.value = temp[1]; form.LastName.value = temp[2]; } </script> </head> <body> <form method="post"> <input type="hidden" name="id"> <input type="hidden" name="FirstName"> <input type="hidden" name="LastName"> <input type='image' id='show,me,data' onclick=formop(this,'add'); src='static/icon16/add.jpg'> <input type='image' id='show,me,data' onclick=formop(this,'edit'); src='static/icon16/edit.jpg'> <input type='image' id='show,me,data' onclick=formop(this,'delete'); src='static/icon16/delete.jpg'> </form> </body> OK I basically have a form field called prepend and if someone enters something in there I want it to prepend to my form action="" how can I insert anything into action ="" depending on what is entered I hope this makes sense. I AM SO LOST <script type="text/javascript"> function SearchGo(){ var searchField = document.getElementById("SearchInput"); var url = "http://url" document.location = url + encodeURIComponent(searchField.value); } </script> //field where URL will be entered and needs to be prepended <input type="text" name="prepend"> //form output is here <form name="searchform" target="_blank" action="";> <input type="button" value="Search" onClick="SearchGo();"/> Hi guys. I was wondering if its possible to switch a form action using javascript. Because im trying to have a search field on my main site for my forum and website. By having two boxes underneath my search field so people can select if the want to search my phpbb forum ore my site. Well anyway, mabey switching the form action is not the right approach. Any tips are welcome thanks. |