473,387 Members | 1,844 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

javascript set hidden fields and post form!

2
right off the bat - im a javascript noob so please forgive the question. im sure it is some stupid bit of syntax that i am missing, but im a middle tier developer trying to help out a friend!

so what im trying to do is post some form data from a javascript function that gets called from an anchor tag.. here are the relevant parts of the page code.

<html>
<head>
<script language="JavaScript">
function setItemDetails(action,id,qty)
{
document.myform.pageAction.value = action;
document.myform.itemId.value = id;
document.myform.itemQty.value = qty;
document.myform.submit();
}

</head>
<body>
<form name="myform" action="http://myserver.com/cart.php" method="post">
<input type="hidden" name="pageAction" value="0" />
<input type="hidden" name="itemId" value="0" />
<input type="hidden" name="itemQty" value="0" />

<a href="javascript:setItemDetails('add_item',12,1)"> Blah</a>
</form>
</body>
</html>

The idea was that the 'cart.php' page would get the POSTed data and use it, but i cant get the javascript function to fire. when i put "alert('test');" in the href of the anchor tag it works, but for some reason it wont call the javascript function i have.

any help would be appreciated.
Apr 5 '07 #1
3 34893
dasien
2
sorry - after reading that post this morning, i realized i forgot the </script> tag. it is there is the code, but i didnt copy it to this message.

Any ideas on what else it could be would be helpful!
Apr 5 '07 #2
acoder
16,027 Expert Mod 8TB
It works fine in Firefox. Which browser are you using?
Apr 5 '07 #3
iam_clint
1,208 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1.  
  2. <html>
  3. <head>
  4. <script language="JavaScript">
  5. function setItemDetails(action,id,qty)
  6. {
  7. alert("test");
  8. document.myform.pageAction.value = action;
  9. document.myform.itemId.value = id;
  10. document.myform.itemQty.value = qty;
  11. document.myform.submit();
  12. }
  13. </script>
  14. </head>
  15. <body>
  16. <form name="myform" action="http://myserver.com/cart.php" method="post">
  17. <input type="hidden" name="pageAction" value="0" />
  18. <input type="hidden" name="itemId" value="0" />
  19. <input type="hidden" name="itemQty" value="0" />
  20.  
  21. <a href="javascript:setItemDetails('add_item',12,1)">Blah</a>
  22. </form>
  23. </body>
  24. </html>
  25.  
worked fine in IE6
Apr 5 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Hennie de Nooijer | last post by:
Hi everbody, Situation I created webpage with a receipt with javascript so when someone orders something from a product list a item is registered on the receipt. This works fine now. The...
1
by: mark.reichman | last post by:
First off.. Thanks to Grant Wagner for help in a previous thread related to this one. I am at a total loss... I have multiple fields in a form with the same name. Lets call the fields with the...
4
by: Fred | last post by:
Hi, i know how to pass a value from Javascript to ASP with a hidden field into a form and submitting it, or with cookies, but here i have to pass a lot of data in an array. There is a list of...
1
by: Sam Wuebben | last post by:
I would like to add a few hidden field values to a form as it is submited via JavaScript. I have a static page shopping site that uses MIVA shopping cart. Some of the pages are getting quite...
5
by: sams | last post by:
I've seen this covered before, but I just don't understand Java very well. I apologize if this is a repeat. Basically, I need a text/java style submit form with multiple hidden fields. It would...
10
by: Mark McLellan | last post by:
Dear all Following the oft-repeated advice here and ciwas I have made my site nearly 4.01 strict (working on it). There are some items on which I would appreciate your advice: 1. Hidden...
0
by: BcNexus | last post by:
Hello all, The search function of this forum isn't working although I found a similar question on the forum using Google, but the replies don't help me. So, forgive me please if this has been...
5
by: dmorand | last post by:
I'm having a strange issue with a form I'm developing. I'm saving some values to hidden fields when a user clicks a button. I setup a function which gets ran on submission of the form, but I also...
11
by: viki1967 | last post by:
Hidden field Hello my friends. This is a htm page that contains a form open in window popUp ( page daughter ). This form insert a value in the one hidden field called "tec", in other form...
1
by: DigDag | last post by:
Hi Everyone, this is my first post here. This may sound weird or silly but I have an HTML form and used javascript to validate fields and I use a CGI to process the data. There are hidden fields...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...

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.