Jump to content

cross browser issues


FARGORE

Recommended Posts

In internet explorer when you have an input type submit, even if there is no form tag, the browser will automatically select the first submit and if you press the enter key it will activate that submit even if you input data to one or more text fields first. This is the desired result I'm looking for. The problem I'm running into is that Firefox and Chrome don't do this. They will automatically select the submit if you place it in a Form tag. But then even if I do not give it an Action it will just reload the page. I can't have it reloading the page it messes up the program. I tried setting a focus to the submit but as soon as you select the text field to enter data the submit loses focus. So what I'm looking for is a way to have a submit button activated in Firefox and Chrome with a press of the enter key, that will not perform an action like reloading the page. The submit has a function call that I want to activate. Is there maybe a way of having a form not perform any action at all? I looked up action in the form section and could not find a reference to doing that. Or have the form do the function call instead of a URL? Any assistance is as always greatly appreciated, than you all again.

Link to comment
Share on other sites

Thank you I'm trying to get this to work but I'm still having trouble. I brought up W3schools try it editor for the onsubmit event handler and replaced the code in the java script function with return false. At first it seems to work, if you type in something and press enter nothing happens. but then if you type in a second time and press enter the program runs like it's supposed to because it is actually still loading the page. If you type in a fake web address for the action it brings up a 404 error Because again it is still reloading the page.

<html><head><script type="text/javascript">function greeting(){return false;}</script></head><body>What is your name?<br /><form name="frm1" action="tryjsref_form_onsubmit.htm" onsubmit="greeting()"><input type="text" name="fname" /><input type="submit" value="Submit" /></form></body></html>

Here is the edited code for the try it yourself example. It does still reload the page. I'm sure your right so am I doing something wrong? I think I understand what you are saying I'm just not executing it right. thank you again for your help sorry I don't quite understand yet.

Link to comment
Share on other sites

If you're using an event attribute, you'll need to use "return greeting()"<form ... onsubmit="return greeting();"> Personally, I prefer to attach event handlers purely with Javascript.

Link to comment
Share on other sites

Thanks again. I did what you say and it worked. I did have to do some extra stuff but that is because there were some specifics about my code that where causing problems. But I managed to figure out how to fix that part on my own (I had to set up an if statement that ran one line of code based on browser) and now it works just the way I want. Thank you for your help I have been working on this issue for quite awhile now.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...