Page 1 of 1

Hidden button

Posted: Wed Mar 24, 2004 3:28 am
by S_henry
Can we make the button invisible? The reason is when we press 'Enter', the form will automatically submit. And I don't want that submit button visible. Can we do that?

Posted: Wed Mar 24, 2004 3:36 am
by markl999
You could do input type="submit" name="submit" value="submit" style="display: none"/> ... but i wouldn't hide it personally as it might cause problems with different browsers (text browsers as an example), or also cause problems for disabled people who are using screen readers/whatever *shrug*

Posted: Wed Mar 24, 2004 3:40 am
by CoderGoblin
You could trap the return key with a javascript event handler and submit the form as an alternative.

Posted: Wed Mar 24, 2004 3:55 am
by Zay
correct me if I'm wrong, but doesn't an enterpress submit the form already by default?

when working in say an input="text" and you press enter you submit the current form...

textarea's and selects don't work with that though.

but if you have a form with textfields only you don't need the submit button at all.

other option if you truly do need a submit thingie:
make a 1px image with same colour as your page background and use that as your submit "button".

give us some more detail about what kind of form it will be, you could also tie js's on it, like CoderGoblin said.

Posted: Wed Mar 24, 2004 3:57 am
by patrikG
Zay wrote:correct me if I'm wrong, but doesn't an enterpress submit the form already by default?
Yes, but if you add 'onSubmit="return false;"' that is disabled. You can then have javascript submit the form with document.forms[0].submit() and thus customise the onSubmit event.

Posted: Wed Mar 24, 2004 3:58 am
by markl999
In some well known browsers of a certain version the submit event isn't 'fired' when you press enter, you have to use the submit button.

Posted: Wed Mar 24, 2004 9:47 am
by Steveo31
markl999 wrote:In some well known browsers of a certain version the submit event isn't 'fired' when you press enter, you have to use the submit button.
Doesn't Opera do that?

Posted: Wed Mar 24, 2004 10:30 pm
by S_henry
For my form, I want to make when I press 'Enter', the form will automatically submit (do some transaction) at another page and return to this page again. Actually if I display the button also can. But for me, if I can hide that button is better. I also not very understand how to use javascript to do this. Can anybody explain more detail? Thanx..

Posted: Wed Mar 31, 2004 7:14 am
by Zay
it seems you need a keyboard Listner or such...

I did a small bit of research for ya...it seems you should call something like this on the onkeypress event... I guess you should put the event on all you form items... (I haven't tested this yet...)

Code: Select all

<html><head>
<script language="javascript">
function myListner(e) &#123;
		var code;
		if (!e) var e = window.event;
		if (e.keyCode) code = e.keyCode;
		else if (e.which) code = e.which;
// XX should be the code for an enter, I don't know the number for it. google should help you with this
		if (code == XX) &#123;
			document.forms&#1111;0].submit();
		&#125;
&#125;
</script>
</head><body>
<form action="target.html" method="post">
<input type="Text" name="blah" size="10" onkeypress="myListner(event)">
</form>
</body>
</html>

Posted: Wed Mar 31, 2004 7:17 am
by twigletmac
Make sure that you use noscript tags to put in a button for those people who do not have JavaScript.

Mac

Posted: Wed Mar 31, 2004 7:56 am
by CoderGoblin
For your information an example of <noscript> tag

Code: Select all

<form name="dosomthing" action="next.php">
<select name="myname" onchange="javascript:submit();"
                 <option value="0">. . .</option>
                 <option value="1">option1</option>
                 <option value="2">option2</option>
                 <option value="3">option3</option>
</select>
<noscript><input type="submit" value="Ok"></noscript>
</form>
Regards

Posted: Wed Mar 31, 2004 8:54 am
by magicrobotmonkey
Yea and you might want to check into where to put the onkeypress() im not sure if it will pick up all keypresses from being in the text field? Maybe in the body tage like onLoad or something?

Posted: Wed Mar 31, 2004 10:14 am
by Zay
magicrobotmonkey wrote:Yea and you might want to check into where to put the onkeypress() im not sure if it will pick up all keypresses from being in the text field? Maybe in the body tage like onLoad or something?
yeah that was my first thought as well...

I think it can be done... You'll need to set up a global keypress listner that checks what key was pressed and then if it's an enter submit the form.

however, you will only be able to submit 1 form.

if you work with onkeypress you could create an extra par stating what form it is using this. then use the submit on the parameter.

I hope this helped.