Post via hidden input types & javascript won't work...

B

b. hotting

Hi,

I don't see why this won't work,
it are 3 links, the last one (a get) does work, but the first 2 won't.
i would like to use a post, through hidden input types
any idea?
thanks for your help!
bjorn



<HTML>
<HEAD>
<TITLE>testing...</TITLE>


<script language="Javascript">

function fAction(MachineID5, ImageFile5)
{
theForm.MachineID.value = MachineID5;
theForm.ImageFile.value = ImageFile5;
theForm.submit());
}
</script>
</HEAD>
<BODY bgcolor="#98D0F8">
<form action="bbb.php" name="theForm" id="theForm" method="post"
TARGET="right">
<input type="hidden" id="MachineID" name="MachineID">
<input type="hidden" id="ImageFile" name="ImageFile">

<A href="javascript:fAction('1','AAA.jpg');">Link to AAA</A><br>

<A href="#" onClick="javascript:fAction(6,'image/BBB.jpg');">Link to
BBB</A><br>

<A href="bbb.php?MachineID=13&ImageFile='image.jpg'" TARGET="right">Link
test</A><br>

</form>

</BODY>
</HTML>
 
B

Bart Van der Donck

b. hotting said:
I don't see why this won't work,
it are 3 links, the last one (a get) does work, but the first 2 won't.
i would like to use a post, through hidden input types
any idea?

[...]
<script language="Javascript">
function fAction(MachineID5, ImageFile5)
{
theForm.MachineID.value = MachineID5;
theForm.ImageFile.value = ImageFile5;
theForm.submit());
}
</script>
[...]

theForm.submit());

should be

theForm.submit();

(syntax error, two brackets)

Hope this helps,
 
B

b. hotting

still doesn't work ;-((

hoped that would do it but it seems its not the only error ;-)



Bart Van der Donck said:
b. hotting said:
I don't see why this won't work,
it are 3 links, the last one (a get) does work, but the first 2 won't.
i would like to use a post, through hidden input types
any idea?

[...]
<script language="Javascript">
function fAction(MachineID5, ImageFile5)
{
theForm.MachineID.value = MachineID5;
theForm.ImageFile.value = ImageFile5;
theForm.submit());
}
</script>
[...]

theForm.submit());

should be

theForm.submit();

(syntax error, two brackets)

Hope this helps,
 
W

web.dev

b. hotting said:
<script language="Javascript">

The language attribute is deprecated use the type attribute instead:

theForm.MachineID.value = MachineID5;
theForm.ImageFile.value = ImageFile5;

Just a matter of personal preference, I like to use the square bracket
notation:

document.forms["theForm"].elements["MachineID"].value = MachineID5;
document.forms["theForm"].elements["ImageFile"].value = ImageFile5;
theForm.submit());

You have an extra closing parenthesis. You could also try:

document.form["theForm"].submit();

<A href="javascript:fAction('1','AAA.jpg');">Link to AAA</A>

The use of pseudo javascript protocol is highly frowned upon. Try at
least using the onclick event handler:

<A href="#" onClick="javascript:fAction(6,'image/BBB.jpg');">Link to BBB</A>

The pseudo javascript protocol has no place in the event handler,
remove it:

<a href = "#" onclick = "fAction(6, 'image/BBB.jpg');">Link to BBB</a>

In the above two links, you'll most likely want to return false so that
link won't get followed. You should also note, for a graceful
degradation, you should provide an actual link, in case the user has
javascript disabled.
<A href="bbb.php?MachineID=13&ImageFile='image.jpg'" TARGET="right">Link
test</A><br>

It seems to me that this link doesn't even need to be within the form,
since you're not submitting the form with this anyway.
 
L

Lee

b. hotting said:
Hi,

I don't see why this won't work,
it are 3 links, the last one (a get) does work, but the first 2 won't.
i would like to use a post, through hidden input types
any idea?
thanks for your help!
bjorn



<HTML>
<HEAD>
<TITLE>testing...</TITLE>


<script language="Javascript">

should be:
function fAction(MachineID5, ImageFile5)
{
theForm.MachineID.value = MachineID5;
theForm.ImageFile.value = ImageFile5;
theForm.submit());

Don't refer to a form simply by its name or id.
That doesn't work in most browsers.

document.theForm.MachineID.value = MachineID5;

or better, pass a reference to the form into the function.
}
</script>
</HEAD>
<BODY bgcolor="#98D0F8">
<form action="bbb.php" name="theForm" id="theForm" method="post"
TARGET="right">
<input type="hidden" id="MachineID" name="MachineID">
<input type="hidden" id="ImageFile" name="ImageFile">

<A href="javascript:fAction('1','AAA.jpg');">Link to AAA</A><br>

<A href="#" onClick="javascript:fAction(6,'image/BBB.jpg');">Link to
BBB</A><br>

Don't abuse the javascript: pseudo-protocol.
Don't submit a form via link without good reason.
Use a normal submit button and set your hidden values in the
onsubmit handler:

<form action="bbb.php"
name="theForm"
method="post"
target="right"
onsubmit="fAction(this,'1','AAA.jpg')">
<input ...>
<input ...>
<input type="submit" value="AAA">
</form>

function fAction(f,MachineID5, ImageFile5) {
f.MachineID.value = MachineID5;
f.ImageFile.value = ImageFile5;
}
 
T

Thomas 'PointedEars' Lahn

web.dev said:
b. hotting said:
theForm.MachineID.value = MachineID5;
theForm.ImageFile.value = ImageFile5;

Just a matter of personal preference, I like to use the square bracket
notation:

document.forms["theForm"].elements["MachineID"].value = MachineID5;
document.forms["theForm"].elements["ImageFile"].value = ImageFile5;

It is not only a matter of personal preference. The latter (yours) is
the standards compliant approach, the former is the proprietary one.
theForm.submit());

You have an extra closing parenthesis. You could also try:

document.form["theForm"].submit();

document.form_s_, as above.


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top