Click to See Complete Forum and Search --> : ? on how to pass function result in form


knipper
04-21-2003, 04:10 PM
Hey guru's...

I have a function that I use to write a variable to a page to create a dynamic link. That works very well.

However, I also want to pass that function result to a hidden field on a form. So when the form is submitted the variable gets written to my database.

Basicaly the dynamically created grabbed variable gets written into the "value" area of my hidden field.

Example: <input type="hidden" name="field1" value="the variable grabbed from the function">

What's the easiest (or best) way to accomplish this?

I tried a few things from some tutorial I found online...but can't get the desired results!

Thanks in advance! :)

pyro
04-21-2003, 05:12 PM
You are going to have to do it in javascript, something like this:

<script language="javascript" type="text/javascript">
function loadvars()
{
document.formname.fieldname.value = yourvar;
}
</script>
</head>
<body onload="loadvars()">

knipper
04-21-2003, 05:19 PM
Thanks....

I gotta get back to my laptop where I have my forms/pages. Before I can try it...

But can I use my function result in the line?

Like this?


<script language="javascript" type="text/javascript">
function loadvars()
{
document.form1.hiddenfield.value = + GetId() +;
}
</script>
</head>
<body onload="loadvars()">


BTW...

Here is what I use to get my result:

<script language="javascript">
function GetId()
{
re = new RegExp("cust=([^&$]*)&?","i");
if (re.test(document.location))
return unescape(RegExp.$1);
else
return "";
}
</script>


Which normally gets placed in a document.write line.

Jona
04-21-2003, 06:09 PM
<script language="javascript" type="text/javascript">
function loadvars(){document.form1.hiddenfield.value = GetId;}
</script>
</head>
<body onload="loadvars()">

knipper
04-21-2003, 08:40 PM
I had to modify slightly but it worked. I wasn't getting the response in my database....then I realized THAT was due to a different setting. A couple tweaks...and it worked!

I actually used:


<script language="javascript" type="text/javascript">
function loadvars()
{
document.form1.hiddenfield.value = GetId();
}
</script>
</head>
<body onload="loadvars()">


Thanks! ;)

Jona
04-21-2003, 08:44 PM
Cool! :)