Solved

Creating a text string from 3 drop down boxes (hopefully pretty easy)

Posted on 2012-03-16
5
225 Views
Last Modified: 2012-03-19
Hi All,

Im pretty new to creating webpages so please be gentle :)

I need a piece of code, php or even a name of an element to create a string from 3 drop down boxes, box1, box2 and box3

Heres an example

Box1 - ford = for, volkswagen = vol, porsche = por
Box2 - red = red, yellow = yel, blue = blu
Box3 - long = lon, medium = med, short = sho

Hence, selecting Volkswagen in box1, yellow in box2 and medium in box3 would produce the string (possibly in a box below the dropdowns) volyelmed (i.e. like a trucated product code)

Hope this makes sense, any help much appreciated.
0
Comment
Question by:johnsit
  • 2
  • 2
5 Comments
 
LVL 1

Expert Comment

by:ScottNL1
Comment Utility
You are submitting a form?

is so, the easy way is:

$string = $_POST['box1']." ".$_POST['box2']." ".$_POST['box3'];

echo $string;
0
 

Author Comment

by:johnsit
Comment Utility
Thanks for the reply,

No, I am not, I simply want to display the string underneath the drop downs on the same page.
Basically it is to give a user a product code by selecting from a drop down.
0
 
LVL 1

Accepted Solution

by:
ScottNL1 earned 500 total points
Comment Utility
try this

<script>


function product_code(){
  var box1 = document.getElementById("box1");
  var box2 = document.getElementById("box2");
  var box3 = document.getElementById("box3");
  document.getElementById("code").innerHTML = box1.options[box1.selectedIndex].value + box2.options[box2.selectedIndex].value + box3.options[box3.selectedIndex].value;

  ;

}


</script>


Car:
<select id="box1" onchange="product_code();">
       <option value="for">ford</option>
       <option value="vol">volkswagen</option>
       <option value="por">porsche</option>
</select>
<br />
Color:
<select id="box2" onchange="product_code();">
       <option value="red">red</option>
       <option value="yel">yellow</option>
       <option value="blu">blue</option>
</select>
<br />
Type:
<select id="box3" onchange="product_code();">
       <option value="lon">long</option>
       <option value="med">medium</option>
       <option value="sho">short</option>
</select>
<br /><br />

<div id="code" style="color:red;font-size:1.2em"></div>

Open in new window

0
 
LVL 53

Expert Comment

by:COBOLdinosaur
Comment Utility
Post a link to the page, or the HTML and we should be able to give you some code.


Cd&
0
 

Author Comment

by:johnsit
Comment Utility
Thanks very much scottNL1, exactly what I was after!
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Video on my site 4 26
PHP Sum Column in Table 3 26
Bootstrap 3 and Angular 2 12 21
while loop in html mail format 5 32
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now