By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,813 Members | 2,269 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,813 IT Pros & Developers. It's quick & easy.

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

P: n/a
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>
Jan 13 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
b. hotting wrote:
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,

--
Bart

Jan 13 '06 #2

P: n/a
still doesn't work ;-((

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

"Bart Van der Donck" <ba**@nijlen.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
b. hotting wrote:
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,

--
Bart

Jan 13 '06 #3

P: n/a

b. hotting wrote:
<script language="Javascript">
The language attribute is deprecated use the type attribute instead:

<script type = "text/javascript">
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 = "fAction('1', 'AAA.jpg');">Link to AAA</a>
<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.

Jan 13 '06 #4

P: n/a
web.dev wrote:
b. hotting wrote:
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
Jan 13 '06 #5

P: n/a
Ran into the same problem a while back, tried a few combinations and
finally got it to work on IE and firefox. Check out:

http://www.suckingfish.com/view.do?crumb_id=dsid_1104

Good luck,

Matt

Jan 13 '06 #6

P: n/a
Thanks guys!
Really appreciated!

Jan 14 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.