?
Solved

GET FORM....combining values

Posted on 2004-11-18
5
Medium Priority
?
193 Views
Last Modified: 2010-04-09
Does anyone know how to combine the value of two text fields when submitting a form?  

Here is an example form:
----------------------------------------

<html>
<head>

<title>Untitled Document</title>
</head>

<body>
<form name="form1" method="get" action="#">
<input name="first" type="text">
<input name="last" type="text">
<input name="submit" type="submit" value="Submit">
</form>
</body>
</html>


This is the submit output:

?first=John&last=Smith&submit=Submit

I would like to combine the two fields and have one value like this:

?name=JohnSmith&submit=Submit


Thanks, Good Luck
0
Comment
Question by:bzak
5 Comments
 
LVL 97

Expert Comment

by:Lee W, MVP
ID: 12617069
You'd get something like that if you did this:

<html>
<head>

<title>Untitled Document</title>
</head>

<body>
<form name="form1" method="get" action="#">
<input name="name" type="text">
<input name="name" type="text">
<input name="submit" type="submit" value="Submit">
</form>
</body>
</html>
0
 
LVL 54

Accepted Solution

by:
Ryan Chong earned 400 total points
ID: 12617123
you need to apply a hidden field, which some javascript, like:

<html>
<head>

<title>Untitled Document</title>
</head>
<script language = "javascript">
   function validate(frm) {
     frm.fullname.value = frm.first.value + frm.last.value;
  return true;
}
</script>
<body>
<form name="form1" method="get" action="" onSubmit="return validate(this)">
<input name="first" type="text">
<input name="last" type="text">
<input name="fullname" type="hidden" id="fullname">
<input name="submit" type="submit" value="Submit">
</form>

</body>
</html>
0
 

Author Comment

by:bzak
ID: 12617159
Thanks ryancys.  That works.  Now what if I only want to submit the fullname?  So just submit that hidden field.
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 12617178
You don't want to use "name" as the name of an argument, it is a reserved word.  I used "fullname" instead:

<html>
<head>

<title>Untitled Document</title>
</head>

<body>
<form name="form1">
<input name="first" type="text">
<input name="last" type="text">
</form>
<form method="get" action="#">
<input name="fullname" type="hidden"
<input name="submit" type="submit" value="Submit"
onclick="thisform.fullname.value=document.forms['form1'].first.value+document.forms['last'].value">
</form>
</body>
</html>


Cd&
0
 

Author Comment

by:bzak
ID: 12617293
Nevermind...I got it...thanks again.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Suggested Courses

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question