General discussion

Locked

Force a Submit on a form load?

By 3wadman ·
How can you click a SUBMIT button using CODE?

I would like to use a form POST or GET in a ASP page without needing the visitor to click the Submit button.

In VB you can click any button by changing the VALUE of the object. Seems like either (windows.object.submit = True or document.all.object(1) = -1) VBSCRIPT or JSCRIPT should be able to trick the browser into sending its 'pair values' to another ASP page.

This conversation is currently closed to new comments.

5 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

Force a Submit on a form load?

by b1xml2 In reply to Force a Submit on a form ...

Try this:-
<html>
<head>
<title>Conditional Submission</title>
<script language="javascript">
var regTrim = /(^\s+)|(\s+$)/g;
function checkData(e) {
trim(e);
if (e.value != "") document.data.submit();
}

//for browsers that support regular expressions
function trim(e) {
var szValue = new String(e.value);
szValue = szValue.replace(regTrim ,"");
e.value = szValue;
}
</script>
</head>
<body bgcolor="#ffffff">
<form name="data" method="get" action="request.asp">
Search: <input type="text" name="search" onchange="checkData(this);">
</form>
</body>
</html>

Notes:-
------
1. It is considered bad "form" (pun intended!) to submit forms without user action.
2. The onchange event is used for input types:- text, password as well as select and textarea elements.
3. The onclick event is used for input types radio and checkbox.
4. Cross browser scripting would require you to check the type. If the supported browsers implement DOM properly, you can check the element.tagName instead of the element.type.
Select elements have two values: select-one and select-multiple.
5. To submit a form via code, use the document.formName.submit() method.
6. It is good to have some validation, trimming leading and trailingspaces client-side. Saves work on the server.
7. Regular Expression is supported in Javascript 1.2 and above. You would have to write your own function
to trim values for older browsers using the substring and charAt methods.
Regards,
Brandon Driesen
Senior Analyst Programmer

Collapse -

Force a Submit on a form load?

by 3wadman In reply to Force a Submit on a form ...

Sorry, this forces the user to gain and loose focus on the input box.

Collapse -

Force a Submit on a form load?

by agibbs In reply to Force a Submit on a form ...

To post a GET to an ASP page, just append the parameters to the URL, like so:

http://www.blabla.com/mypage.asp?textbox1=name&textbox2=address&textbox2=city . . .

To post a POST to an ASP page, use a JavaScript snippet something like so (assuming your form's name was "form1"):

<script language="javascript">
document.form1.Submit();
</script>

--Aaron

Collapse -

Force a Submit on a form load?

by 3wadman In reply to Force a Submit on a form ...

That worked well, thanks!

FYI: Form POST is the only easy way to securely send record set fields from a SQL to a SSL without the users knowledge.(You lose your seesion variables when you go from non-SSL to SSL)

Collapse -

Force a Submit on a form load?

by 3wadman In reply to Force a Submit on a form ...

This question was closed by the author

Back to Web Development Forum
5 total posts (Page 1 of 1)  

Related Discussions

Related Forums