469,330 Members | 1,284 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,330 developers. It's quick & easy.

creating a form element in a function?

Hello,

I have a form that I want to submit "onchange", OK I've got that working, but when the
form submits, I want to pass along a value to a CGI script, as if that value was in a
hidden form element.

BUT, I don't want that value to be in the actual HTML form, I want it to be created in my
submit function.

For instance:
Expand|Select|Wrap|Line Numbers
  1. <script language="JavaScript" type="text/javascript">
  2. <!--
  3. function submit_this() {
  4.  
  5. // right here I would define a name value pair to send
  6. var go_update = 'true';
  7.  
  8. // now I want to send this along with the form data
  9. document.form_name.submit();
  10. }
  11. //-->
  12. </script>
  13.  
Any suggestions on how I might do this?
Do I need to define a form element in my function?
I can't find anything on this.

Thanks,

dstefani
Jul 23 '05 #1
1 1740
In article <dy*******************@newssvr29.news.prodigy.com> ,
Don Stefani <no********@yahoo.com> wrote:
Hello,

I have a form that I want to submit "onchange", OK I've got that working, but
when the
form submits, I want to pass along a value to a CGI script, as if that value
was in a
hidden form element.

BUT, I don't want that value to be in the actual HTML form, I want it to be
created in my
submit function.

Please explain why a hidden field will not work for you.

If a field is not null, the field data will be sent to the host. Null
fields are not sent to the host. How can a hidden field cause you
problems?

You could create the hidden field dynamically, but a static hidden field
seems easier.

Here is a post about creating dynamic form fields
Re: How to expand the number of fields in a form? :
http://groups.google.com/groups?q=ma...group:comp.lan
g.javascript&hl=en&lr=&ie=UTF-8&oe=ISO-8859-1&selm=MPG.1af1b944853eff5498
9da2%40nntp.lucent.com&rnum=1

Here is an example using a static hidden field:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>A sample form</title>

<SCRIPT type="text/javascript">
function changeForm()
{
document.forms[0].the_current.value = "filled with data";
alert("form input value = " +
document.forms[0].hours.value +
" hidden value = " +
document.forms[0].the_current.value);
}
</script>

</head>
<body>
<form action=
"http://www.mindspring.com/cgi-bin/cgiemail"
method="post" name="payroll"
onSubmit="changeForm()">
<input type="hidden" name="the_current" value="">

<b>How many hours did you work this week?&nbsp&nbsp</b>
<input type="text" name="hours" size="6" maxlength="3"><br>

<input type="submit" name="submit" value="Process form">&nbsp&nbsp
<br>
<input type="reset" name="reset" value="Reset Form">
</form>
</body>
</html>

Please note that I have not verified that the the field data was sent to
the host.

Robert
Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

72 posts views Thread by Stephen Poley | last post: by
12 posts views Thread by CJ | last post: by
3 posts views Thread by Skippytpe | last post: by
2 posts views Thread by pshvarts | last post: by
4 posts views Thread by jedimasta | last post: by
9 posts views Thread by whisher | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by Purva khokhar | last post: by
reply views Thread by haryvincent176 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.