/    Sign up×
Community /Pin to ProfileBookmark

Passing Multiple Variables in Form

In a regular form with text fields, can I pass the imput from the user directly into a hidden textarea from multiple fields intertwined with html? Example:

<form>
<input type=”text” name=”firstname”>
<input type=”text” name=”lastname”>
<input type=”text” name=”occupation”>
<input type=”hidden” value=”some html + firstname + some html + lastname + some html + occupation”>
</form>

I think this might require some javascript. Is something like this possible?

to post a comment
JavaScript

9 Comments(s)

Copy linkTweet thisAlerts:
@FangOct 01.2008 — Why do this? The information is already in the form.
Copy linkTweet thisAlerts:
@Becca800authorOct 02.2008 — It's a long story, but it is what is needed to be done. How can this be done? Just a small example from someone please...
Copy linkTweet thisAlerts:
@ShortsOct 02.2008 — I'm guessing something like:
[code=html]
<html>
<head>
<script type="text/javascript">
function chgHidden(the_field) {
var the_hidden = document.getElementById('the_hidden');
the_hidden.value = the_hidden.value+' & '+the_field.value;
}
</script>
</head>
<body>
<form>
<input id="the_first_name" type="text" name="firstname" onblur="chgHidden(this);" />
<input id="the_last_name" type="text" name="lastname" onblur="chgHidden(this);" />
<input id="the_occupation" type="text" name="occupation" onblur="chgHidden(this);" />
<input id="the_hidden" type="text" value="test" />
</form>
</body>
</html>
[/code]


Would suggest you make it more sophisticated, but this should help give you a start.
Copy linkTweet thisAlerts:
@Becca800authorOct 02.2008 — Thanks shorts. With this line:

[CODE]the_hidden.value = the_hidden.value+' & '+the_field.value;[/CODE]

Do I substitute the second 'the_hidden.value' with the html? And will regular html parse okay in this line with the < and >'s? And with 'the_field.value', do I replace this with the_first_name.value for example? And finally (sorry....js idiot here), do I add this +' & '+ between each segment?
Copy linkTweet thisAlerts:
@ShortsOct 02.2008 — Thanks shorts. With this line:

[CODE]the_hidden.value = the_hidden.value+' & '+the_field.value;[/CODE]

Do I substitute the second 'the_hidden.value' with the html? And will regular html parse okay in this line with the < and >'s? And with 'the_field.value', do I replace this with the_first_name.value for example? And finally (sorry....js idiot here), do I add this +' & '+ between each segment?[/QUOTE]


the_hidden.value is whats currently in your INPUT that is hidden. The input with the ID 'the_hidden', which we are getting with document.getElementById('the_hidden')

and the_field.value does not need to be changed, since it is caught by function chgHidden([B]the_field[/B]).

the ' & ' is what you would have as spacers between the new code and previous code.
Copy linkTweet thisAlerts:
@Becca800authorOct 02.2008 — Oh my God, I got a lot of sleep last night and I swear I haven't had any alcohol yet (its still early) but I still don't get it. I don't understand how I will get the html I need into the hidden field with the values from the other fields in certain positions.

So that the hidden value would be <html>+field value 1+<html>+field value 2 etc etc etc
Copy linkTweet thisAlerts:
@ShortsOct 02.2008 — In that case, you would want it to be more like:
[CODE]
function chgHidden() {
var the_hidden = document.getElementById('the_hidden');
the_hidden.value = '<html>'+
'<tags>'+
document.getElementById('the_first_name')+
'</tags>'+
'<tags>'+
document.getElementById('the_last_name')+
'</tags>'+
'<tags>'+
document.getElementById('the_occupation')+
'</tags>'+
'</html>';
}
[/CODE]


etc.
Copy linkTweet thisAlerts:
@Becca800authorOct 02.2008 — Shorts rocks. I figured it out, or, rather, you figured it out.
Copy linkTweet thisAlerts:
@ShortsOct 02.2008 — Awesome, thanks. And glad to hear you got it working.
×

Success!

Help @Becca800 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.27,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...