473,796 Members | 2,586 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

onClick submitForm()

I need to submit a form using a hyperlink, and I need to pass a
variable associated with that hyperlink.

Example: I have a page where employees enter event information, and
they are supplied a dropdown box to pick the promoter for that event.
If the promoter does not exist in the database, they need to add
him/her to the database so that the promoter can be associated with
the event. If the promoter does not exist, I want to provide a link
(Add Promoter), that will submit the form, and pass a variable to the
query page, either in the form scope or url scope, that is
"mode=addPromot er", so that I can take them immediately send them to
the promoters page, and then I will take them back to the event page
to fill in the rest of the information.

So, in a nutshell, I need to submit a form using a hyperlink, and to
also pass a variable in either the url scope or form scope.

Any help is greatly appreciated.
Jul 20 '05 #1
14 28140
Erik wrote:
I need to submit a form using a hyperlink, and I need to pass a
variable associated with that hyperlink.
You don't need to and you don't want to.
Example: I have a page where employees enter event information, and
they are supplied a dropdown box to pick the promoter for that event.
If the promoter does not exist in the database, they need to add
him/her to the database so that the promoter can be associated with
the event. If the promoter does not exist, I want to provide a link
(Add Promoter), that will submit the form, and pass a variable to the
query page, either in the form scope or url scope, that is
"mode=addPromot er", so that I can take them immediately send them to
the promoters page, and then I will take them back to the event page
to fill in the rest of the information.


A submit button with another `name' and/or `value' attribute
value than the default submit button will serve that purpose
and won't require neither support of client-side JavaScript
nor unreliable and time-consuming changes to the `action'
value of the form.
PointedEars
Jul 20 '05 #2
I understand that possibility, but I need to use a hyperlink.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #3
Erik H wrote:
I understand that possibility, but I need to use a hyperlink.


You may want to explain why you think a hyperlink is necessary.
FWIW, here you are:

<a
href="javascrip t:doSomethingWi thTheActionAttr ibute(...);docu ment.forms[...].submit();"
onclick="doSome thingWithTheAct ionAttribute(.. .);
document.forms[...].submit(); return false;">Submit</a>

will also serve the purpose if client-side JavaScript is supported
and the `action' attribute of the `form' element can be manipulated
by assigning values to a property of the respective DOM object and
submitting forms by scripts is allowed.

The doSomethingWith TheActionAttrib ute(...) function is up to you,
however, depending on the values the resource specified with the
`action' attribute expects.
PointedEars
Jul 20 '05 #4
Thomas 'PointedEars' Lahn <Po*********@we b.de> writes:
<a
href="javascrip t:doSomethingWi thTheActionAttr ibute(...);docu ment.forms[...].submit();"
onclick="doSome thingWithTheAct ionAttribute(.. .);
document.forms[...].submit(); return false;">Submit</a>


There is no need to have a javascript:-URI in the href. If the browser
supports javascript, then the onclick will work. If not, the href
won't work either. That is, there is almost never any need for a
javascript:-URI.

It is better to let the href point to an HTML page that makes sense.
Either a page that works without the javascript, or that lets the
server perform the action that the client-side javascript couldn't,
or just a link to a page that explains that this page needs javascript.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #5
The reason for using a hyperlink is aesthetics. Using a button would
definitely be simple, I use that for this type situation in other places,
but here I want/need to use something small, so either an image or a
hyperlink would work best.

My javascript abilities are still novice, so I'm a little lost with what
you suggested. My basic experience tells me that I can use
<a href="#" onclick="submit Form()">Add Promoter</a>, and then create a
function that will in turn submit the form, and at the same time pass the
variable of 'mode=addPromot er'. I am using ColdFusion, so I can pass the
variable in either the form or url scope.

Also, what I can use here will work when the user needs to edit the
promoter, so I can pass 'mode=editPromo ter' on a different page.
Jul 20 '05 #6
Lasse Reichstein Nielsen wrote:
Thomas 'PointedEars' Lahn <Po*********@we b.de> writes:
<a
href="javascrip t:doSomethingWi thTheActionAttr ibute(...);docu ment.forms[...].submit();"
onclick="doSome thingWithTheAct ionAttribute(.. .);
document.forms[...].submit(); return false;">Submit</a>
There is no need to have a javascript:-URI in the href.


But there is.
If the browser
supports javascript, then the onclick will work. If not, the href
won't work either. That is, there is almost never any need for a
javascript:-URI.
Please note that event handlers are standardized, `javascript:' URIs are
not. The latter is `common practice' anyway, so the above combination has
a 100% chance to work if client-side JavaScript is supported and enabled.
It is better to let the href point to an HTML page that makes sense.
Either a page that works without the javascript, or that lets the
server perform the action that the client-side javascript couldn't,
You forgot that the form data to be submitted is then lost, so the
Good Thing you are suggesting and I generally agree with is AFAIS
not applicable here.

If you want people without JavaScript to submit forms, use form buttons
in the first place. If you don't like their look, use CSS to format them,
or use <input type="image" ...> for submit buttons (but note that Netscape
4.x users are then excluded.)
or just a link to a page that explains that this page needs javascript.


Doing that is the best way to piss off users. The better way is to write
that hyperlink dynamically using DOM scripting, document.write( ...) or
HTMLElement.app endChild(...), respectively.

And the best way is to discard hyperlinks for form operation, use
server-side scripting where possible, and use client-side scripting
if it reduces traffic (ref.: form validation.)
PointedEars
Jul 20 '05 #7
Thomas 'PointedEars' Lahn <Po*********@we b.de> writes:
Lasse Reichstein Nielsen wrote:
If the browser supports javascript, then the onclick will work. If
not, the href won't work either. That is, there is almost never
any need for a javascript:-URI.


Please note that event handlers are standardized, `javascript:' URIs are
not. The latter is `common practice' anyway, so the above combination has
a 100% chance to work if client-side JavaScript is supported and enabled.


Do you know of *one* browser where the javascript:-URI works and the
onclick attribute doesn't? If there isn't one, there is no need for
the URI, since it will only ever be used by non-javascript browsers.
You forgot that the form data to be submitted is then lost, so the
Good Thing you are suggesting and I generally agree with is AFAIS
not applicable here.
That is a point. If there is another way to submit the form when
Javascript is off, then clicking the link can be a problem. The
javascript:-URI doesn't appear to do anything with Javascript off.
If you want people without JavaScript to submit forms, use form buttons
in the first place.
If you want people *with* Javascript to submit forms, use form buttons
anyway. That is what the user expects.

If a form uses a link instead of a submit button, I would easily be
confuzed about how to submit it.
or just a link to a page that explains that this page needs javascript.


Doing that is the best way to piss off users.


Is it so much better than making a page that fails completely if
Javascript is disabled? At least this way, the user will know what
went wrong.

However, I must admit that when I suggest such a link, it is partly
because I want the try to write the explanation for why his site cannot
work without Javascript. It can be an eye opener.
The better way is to write that hyperlink dynamically using DOM
scripting, document.write( ...) or HTMLElement.app endChild(...),
respectively.
That is a solution. If the link is vital to the page, the entire
page can be written that way.
And the best way is to discard hyperlinks for form operation,
Definitly!
use server-side scripting where possible, and use client-side
scripting if it reduces traffic (ref.: form validation.)


Yep,
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #8
Erik wrote:
The reason for using a hyperlink is aesthetics.
You should learn that esthetics must always be implemented
in a way that does not oppose usability to be successful.
Using a button would definitely be simple, I use that for this type
situation in other places, but here I want/need to use something small,
so either an image or a hyperlink would work best.
What is it that you don't like `<input type="image" ...>'?
My javascript abilities are still novice, so I'm a little lost with what
you suggested. My basic experience tells me that I can use
<a href="#" onclick="submit Form()">Add Promoter</a>, and then create a
function that will in turn submit the form, and at the same time pass the
variable of 'mode=addPromot er'.
No, the user-defined submitForm() method must change the `action'
property of the DOM form object and *then* call its submit() method:

function submitForm(oFor m)
{
if (oForm && typeof oForm.action != "undefined" && oForm.submit)
{
oForm.action = "foobar";
oForm.submit();
}

return false;
}

<a
href="javascrip t:submitForm(do cument.forms[...])"
onclick="return submitForm(docu ment.forms[...]);">Submit</a>
I am using ColdFusion, so I can pass the
variable in either the form or url scope.
You could also manipulate the `value' property of a DOM `input'
object and then call the submit() method of the form object:

function submitForm(oFor m)
{
if (oForm
&& oForm.elements
&& oForm.elements["foo"]
&& oForm.elements["foo"].value)
&& oForm.submit)
{
oForm.elements["foo"].value = "bar";
oForm.submit();
}

return false;
}

Maybe it is required to use the setTimeout(...) function
to wait a few (milli)seconds before submitting the form:

setTimeout('doc ument.forms[...].submit()', 42);
Also, what I can use here will work when the user needs to edit the
promoter, so I can pass 'mode=editPromo ter' on a different page.


You need to pass $promoterID to that page,
too, using one of the suggested solutions.
PointedEars
Jul 20 '05 #9
Lasse Reichstein Nielsen wrote:
Thomas 'PointedEars' Lahn <Po*********@we b.de> writes:
Lasse Reichstein Nielsen wrote:
> If the browser supports javascript, then the onclick will work. If
> not, the href won't work either. That is, there is almost never
> any need for a javascript:-URI.
Please note that event handlers are standardized, `javascript:' URIs are
not. The latter is `common practice' anyway, so the above combination has
a 100% chance to work if client-side JavaScript is supported and enabled.


Do you know of *one* browser where the javascript:-URI works and the
onclick attribute doesn't?


No, but that is irrelevant.
If there isn't one,
Although I (or you) don't know one, there may be one.
there is no need for the URI, since it will only ever be used by
non-javascript browsers.
You don't get the point. UAs that don't know the event handler will ignore
it and access the URI, while UAs that are standards-compliant will ignore
the URI since the event is canceled with the last statement in the handler.
You forgot that the form data to be submitted is then lost, so the
Good Thing you are suggesting and I generally agree with is AFAIS
not applicable here.


That is a point. If there is another way to submit the form when
Javascript is off, then clicking the link can be a problem. The
javascript:-URI doesn't appear to do anything with Javascript off.


OK, maybe I made myself not clear enough: The hyperlink to an alternative
document that is accessed when JavaScript support is not available, is in
*this* case complete nonsense since the form data provided (namely the
promoter's name to add) is then lost.
If you want people without JavaScript to submit forms, use form buttons
in the first place.


If you want people *with* Javascript to submit forms, use form buttons
anyway. That is what the user expects.

If a form uses a link instead of a submit button, I would easily be
confuzed about how to submit it.


Full ACK.
> or just a link to a page that explains that this page needs javascript.


Doing that is the best way to piss off users.


Is it so much better than making a page that fails completely if
Javascript is disabled? At least this way, the user will know what
went wrong.


You mean they know then that the webauthor is incompetent
enough not to foresee that certain possibility. Great.
However, I must admit that when I suggest such a link, it is partly
because I want the try to write the explanation for why his site cannot
work without Javascript. It can be an eye opener.


You played the devil's advocate again? ;-)
The better way is to write that hyperlink dynamically using DOM
scripting, document.write( ...) or HTMLElement.app endChild(...),
respectively.


That is a solution. If the link is vital to the page, the entire
page can be written that way.


No, that would be definitely a Bad Thing unless users without JavaScript
don't get there in the first place, i.e. it is not even listed in search
engines. But you then can disregard users without JavaScript anyway and
the time-consuming and sometimes hard-to-read DOM scripting is no longer
required.
PointedEars
Jul 20 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
3690
by: Shock | last post by:
Hello everyone, I am having a problem with the program below. I have isolated the problem to the onclick event that is located throughout arrQuestions. The onclick event refers to a function and passes it two parameters. For the life of me I cannot figure out what the error is, but one occurs everytime I click a &%*$&# radio button. Also, the function only alerts the user immediately as to what question/answer they clicked. I am...
17
61445
by: Mike Gratee | last post by:
Is it possible to use JavaScript to cause the browser to click a link on a page and have the browser act exactly like the user had clicked on the link directly? In other words, I need to programmatically issue a JavaScript statement which causes the browser to act just like the user clicked on a link in my page. And if that link has an onClick JS event defined, I'd want that onClick event to execute too, exactly the same as if the user...
2
9183
by: Kevin Lyons | last post by:
Hello, Can anyone assist me with what I am trying to do with the following code (six different scenarios to try to make the functionality work correctly)? I want to always (and ONLY) display in the status bar 'Symantec Corporation' whenever anyone mouses over (onMouseOver) my image or link OR when one clicks while holding the left mouse down (onClick) on the same image or link. Upon releasing the mouse (onMouseOut), the
3
3271
by: Jamie Jackson | last post by:
I'm rewriting all links' onclick events, but I'm having a problem. The onclick event that I'm inserting works correctly in Opera, but not in FF or IE. I'm retroactively adding the statement "return promptBeforeOpening();" FF and IE rewrite it as I would expect them to, but it turns out that that doesn't work (no disclaimer pops up, and the link is not disabled):
2
18581
by: RobG | last post by:
I am trying to dynamically add an onclick to an element, however I just can't get the syntax right. consider the following function: function doClick (evt,x) { // do things with evt and x } Which is called statically by: <button onclick="doClick(event,this);">Click me</button>
2
3293
by: Sedef | last post by:
Hi, i'm trying to create a custom Button user control which will be derived from System.Web.UI.WebControls.Button. the normal server side Button class creates some client side javascript code for its onclick event. it's something like: <input type="submit" name="Button1" value="Button" onclick="if (typeof(Page_ClientValidate) == 'function') Page_ClientValidate(); " language="javascript" id="Button1" /> what i want to do is to be able to...
6
7175
by: Nx | last post by:
i've got it all working nicely in firefox, but whenever i test it in IE none of the onclick events are triggered. i'm using an xsl to transform an rss feed into a photogallery. when i try to use setAttribute FF and safari work, but IE stops working when i used addEventListener and attachEvent safari stops working and when i tried .onClick,none of them worked being fairly inexperienced (but learning fast), i figure i'm doing it
7
2795
by: extremerep | last post by:
My task is to change the value of a button and then make it functional with the onClick handler. Changing the value to "Play Again" works, but making the onClick work accordingly does not. The following is a snippet of the script. What is keeping it from working? function displaycards1(){ document.form1.reveal1.value="Play Again"; document.form1.reveal1.onClick="setcards();"; } </script>
9
7149
by: poml | last post by:
Hello, first time posting on thescripts.com, and I'm in dire need of some help. All I want to do is disable the submit button (not the entire form) onClick, and am wondering if this is possible. Here's the current coding: <form enctype="multipart/form-data" action="?id=completeupload" name="submitform" method="POST"> <b>File to Upload:</b>&nbsp;<input name="userfile" size="50" type="file"><br><br> <span class="class3"> <input...
0
10465
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10242
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9061
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7558
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6800
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5453
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5582
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4127
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2931
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.