Can't Load Image Within Onsubmit Form Event On Safari
Aug 25, 2011
I want to load an image with JS within the form event "onsubmit" without stipping the submit action of the form.
What I do is the following:
var img = new Image();
img.onload = function(){
myfunction();
};
[Code]....
This logic is a MUST for me, I mean I don't want to use settimeout to postpone the form submit, and I have to call the URL_FOR_PHP_SCRIPT_TO_DO_SOME_LOGIC this way since this code is on a JS file from different domain. This logic works fine on all browsers, and the request to call the image is sent -which is what exactly I need-, however on safari it doesn't call the image request, and start posting the form directly. I tried to add an "onunload" event on the page containing the form when the browsers is safari, but this didn't help too, and the form still submitting data directly without starting sending the request to load the image.
I have a site which displays a selection of advert listings. We log the number of clicks each advert receives via ajax requests.The listings link to both internal pages on our site and external pages, hence the ajax - we cannot log the'clicks' by logging the requests on the destination pages as these are not all on our site for us to log. Also, I don't want to potentially get false positives e.g.from bookmarked pages - hence I am logging the actual clicks, not the requests on the destination.
All is OK in most browsers, but there is a problem with Safari (I am running Safari 4.0 on Windows XP running in Virtualbox OSE) but only where the destination is to open in the same window/tab (some listings go to a new window, some don't). I am logging clicks via an ajax request in the onclick event, which is working fine when the listing is to open in a new window, but it appears that when a new window is not to be opened, the ajax never gets sent.A have constructed the following minimal test case:
index.html
Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" [code].....
Note the line commented '****' in index.html which cancels the action of the link. When this is not commented out, the ajax request is sent correctly. Without it (the desired situation) the ajax request never gets sent. Its as if Safari saves up the ajax requests to do later, but never sends them as the new page cancels all such 'saved up' actions.I am using the Safari web developer tools, but I have also checked this test case by checking the Apache logs. Note that as a test case I don't pretend that it will work in IE, but it should work in standards compliant browsers and has been tested on Firefox 3.6.6 and Opera 10.6. The Apache logs show that logger.txt is being requested, unless it is already in the browser cache.Possible workarounds I've considered, but would prefer to avoid:
On the site in question the only such links that currently open in the same window are internal, so I do have the option of logging safari clicks by logging these requests as opposed to clicks and checking the http referer on the server side. As this is not a very flexible solution as it relies on these specific circumstances, also relies on all other links successfully making a new window, and furthermore relying on http referer could result in false negatives I'd rather find a solution within the javascript.I haven't checked whether an asynchonous request would work, but I don't wish to do this anyway just in case there is ever a server problem that prevents the response coming back (note that for these purposes the response is actually superfluous - we are sending the server a message but don't need anything back). I also want to avoid the delay in sending the user to the destination - there is no point having to wait for a response we don't need.Lastly, and my prefered workaround unless I can find anything better, is to make Safari (only) open all links in a new window anyway.
I am trying to redirect users to a payment page after they complete the registration form. After researching a little bit I got the below code to work .. however it triggers even before the registration form is submitted.I would like the below code to trigger when the user clicks on the registration form Submit button. How can I associate the SUBMIT button to the below code.
I have a page with several different forms. One of these currently has an onsubmit event to run a custom validation program before the action is triggered. This event is currently shown asonsubmit="return validateForm(this)"and works as expected.
I want to be able to use this form in some instances without this validation so I want to take this event out and add it if a certain field has been set before the page was loaded. I'm new to jQuery and thought I'd understood how I could do this but I'm not getting this to work.
First of all I added a class of 'mainform' to this form and then used the following to set the event:
I've tried putting line 4 in quotes but it still doesn't work. What am I doing wrong?
I am trying to create a form that writes text to an HTML canvas when submitted. Eventually, the function that writes the text will be more complex. The problem is the text only appears briefly, because the function is only called once when the form is submitted. I want the function to be called continuously after the form is submitted.How do I do this? I have had very little experience with JS.A lame (failed) attempt...
On the very next line I am attempting to bind a submit event handler to the form:
$('#loginform').submit(function() { $.post('member.php', $(this).serialize(), function(data, status) { data = eval('(' + data + ')'); if (data.msg) {
[Code].....
The form is loading fine, but for some reason the submit() is not getting attached to the form. Therefore when I submit it is running member.php from the form "action". Ultimately, I want to be able to run member.php from $.post() so that I can tell member.php that JavaScript is enabled.
I have two frames. Frame "search" contains a search form specifying an onsubmit action like so:
<form ... ... </form>
The other frame contains a <img ... where the perform_search function is defined as follows:
<script language="JavaScript"> function perform_search() { var frame = parent.frames.search; var form = frame.document.forms.mainForm; form.submit(); } </script>
Now, when hitting Return in the search form, then foo() is called fine. But when clicking on the <img ... in the other frame, foo() is NOT called.
Is expclicitly calling foo() from perform_search() the only way to do it, or is there a magic incantation that might do what I want?
II'm running Joomla 1.5.23 and I've been trying to get validation on a component's form fields. In the header section, I'm properly loading the validator.js file, which contains the following:
//function to check empty fields function isEmpty(strfield1, strfield2) { strfield1 = document.forms[0].firstname.value strfield2 = document.forms[0].lastname.value[code]....
My problem is that even if all fields are empty it will go to the next step.
I have been searching high and low and I can't seem to find an answer. I am new at JS and I have created an form and when I click the on submit button it resets all the fields. The fields are always blank after I click reset. I have been working on this for 6 hours.
It just keeps resetting when I click Submit. I see for a millisecond that the total appears but then disappears along with the amount I put in the input text box.
I have created a simple form for uploading text files.You can see two versions of this it at: http:[url]....The form created with static HTML, works fine in current versions of the major browsers.However the dynamic form, fails (only) in IE.It fails because IE does not send the file at all when the form is submitted.
1.The user presses 'Submit Answers' button,which ends the exam and his result is displayed.This one is working fine.
2.The other is the timer expires.the exam finishes and the user's result should be displayed.This one is giving me a problem.
When the timer expires I want to run the onsubmit() function to assign values to hidden form inputs ,but I am unable to do so.How do I do this.Everything else with the timer function is working fine. Only a snippet of the actual code is given here,because the rest of it is ,I believe,irrelevant to the discussion.
I just noticed that if I use a "submit" button the "onSubmit" function call will be invoked. But if I use a button to call some other javascript and at the end of that javascrip I do something like "form.submit()" the "onSubmit" function call will NOT be invoked. I thought that was wierd. Can anyone shed some light? Here's a small example:
<script type="text/javascript"> function subform() { document.frm1.submit(); } function checkform() { alert('checking form'); return true; } </script> </head>
BUT $script_start_time must be populated at the exact moment the submit button is pressed, and not when the page where the form is first visited. Which is why I need a client side solution.
I am using Form in a PHP Code - which post the results to another external - application, and i would like to save some recordes in DB (when someone use the submit button) before moving on to the external-app. how could i do this in a javascript or is it possible?
I am in a JavaScript college class and right now we are learning about form validation, well before server side validation, and I am having an issue with validating the field if the user updates it and hits submit again. The red .setAttribute function is not removed. My code is below, please excuse the noobness I am displaying here.
I have created web pages that do client-side form validation using the onclick directive. E.g.,
<form action=other_page.cgi method=post> Enter your age: <input name=age> <input type="submit" value="" validate_form()"> </form>
where validate_form() returns true or false depending on whether the user entered a valid age.
This does what I want almost everywhere (e.g., Firefox on FreeBSD, Safari on Mac, IE on Win2000) but recently I have become aware of an exception: IE on WinXP.
On WinXP's IE, validate_form() is called (and will display an alert box if that's that's what I coded), but whether it returns true or false, the form is submitted. (Then we do the server-side validation and throw up an error page, but I'd rather catch this client-side.)
So the question I have is: why is WinXP so weird about this? Previous versions of IE didn't do this.
While looking into this, I've discovered I can also do an onsubmit check in the form tag, e.g.,
Is onsubmit new or has it been around for a while? Can I trust old Mozillas on Linux to do the right thing with it? Windows is actually a small portion of the target audience, but I like to make things work for everyone.
Does it make a difference if the form is submitted to the same page or a different page? I don't have ready access to Windows XP to test this out.
I'm trying to create a form whose onsubmit returns false if the form should not be submitted. Normally this type of thing works great for me:
<form onsubmit="return somefunction()">
where somefunction returns false. But I'm trying to do some thing where in some script block, the function gets added:
form.attachEvent("onsubmit", function () { return somefunction() });
(not worrying about crossplatformosity, sorry). But that doesn't work, the form is always submitted. Is there something else I need to be doing to make this happen?
I have the following form working with on onsumbit function, but I would like to change it so that instead of having to click the purchase button to see total price, you only have to change the quantity text box input. I just can not seem to get it to work.
<script language="javascript" type="text/javascript"> function checkQuantity(frm) { var succesful = false; var numQuantity; numQuantity = parseInt(frm.Quantity.value); var numTotalPrice;
if (numQuantity != 0) { numTotalPrice = numQuantity * 4; frm.TotalPrice.value = numTotalPrice; //new String(numTotalPrice); successful = true; } else { alert("Sorry must order more than 0"); successful = false; } return succesful; } </script>
I am wondering if it is possible for me to replace my form submit button with an animated gif (fake progress bar), after the button has been pressed.Having so far disabled the button onclick, I would instead be happy if I could simply change the button text from 'Click here to submit' to 'Processing...'I have done some searches here but I'm finding references to innerHTML, etc., and I'm getting lost now.
I would like to set up an image gallery so that when customer clicks on their chosen image, the image caption populates into the associated field in the form below the gallery, on the same page.
I am not really a coder, I only know this and that
In firefox, this script works just fine. But in safari, it doesn't do anything and I can't figure out why.The intention of this code is to just create a draggable item.