Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Text Heading based on contents of Option dropdown

Posted on 2006-06-22
5
Medium Priority
?
193 Views
Last Modified: 2010-04-06
Hi,

I'll simplify the problem I'm having to it's barest bones - hope it makes sense.

I have a form on which there is a "search text"  text box and a "search by" dropdown list.  Lets assume that this list only has two values :

  <select name="select">
    <option value="INT">Option A</option>
    <option value="NAM">Option B</option>
  </select>

However, the users can come to this form by two means.  Depending on which method they used to get here a different option value will be selected.

For instance if they had followed linka it would look like :

  <select name="select">
    <option value="INT" selected>Option A</option>
    <option value="NAM">Option B</option>
  </select>

if they had followed linkb it would look like

  <select name="select">
    <option value="INT">Option A</option>
    <option value="NAM" selected>Option B</option>
  </select>

How, using HTML or java can I add a line of text on the page which is linked to the selected option.  eg.  If I wanted to display :

"You have arrived here from linka"

or

"You have arrived here from linkb"

Hopefully that makes sense!
0
Comment
Question by:JoHarris
  • 3
5 Comments
 
LVL 10

Expert Comment

by:jagadeesh_motamarri
ID: 16962364
you just need to get the context path and print accordingly...

Pseudo Code: (JSP)

String str = request.getContextPath();
<%
if(str="lina")
out.write(You have arrived here from linka);
else
out.write(You have arrived here from linkb);
%>


____Jags.
0
 
LVL 10

Expert Comment

by:jagadeesh_motamarri
ID: 16962379
Or else simply you can just pass simple hidden variable and do a simple if condition on that...

____Jags.
0
 
LVL 30

Accepted Solution

by:
callrs earned 2000 total points
ID: 16963156
<html>
<!-- FORM: SUBMIT & EXTRACT FORM DATA   - DEMO        -->
<!-- Save the form as "c:\temp\p9.htm" & Then run it -->

<!-- By EE member www.experts-exchange.com/M_876428.html   
     with parse code from www.eggheadcafe.com/articles/20020107.asp "Parsing The Querystring with Javascript -->

<script type='text/javascript'>

 // Parse the query string (part after "?" in the URL)
function parseQ(q) {
      if(q.length > 1) this.q = q.substring(1, q.length);
      else this.q = null;
      this.keyValuePairs = new Array();
      if(q) {      for(var i=0; i < this.q.split("&").length; i++) {      this.keyValuePairs[i] = this.q.split("&")[i];      }      }
this.getKeyValuePairs = function() { return this.keyValuePairs; }

 // Retrieve a value for a key
this.getValue = function(s){
      for(var j=0; j < this.keyValuePairs.length; j++) {
            if(this.keyValuePairs[j].split("=")[0] == s)
                  return this.keyValuePairs[j].split("=")[1];
            }
      return false;
      }

 // Optional code - Array of all parameters
this.getParameters = function() {
      var a = new Array(this.getLength());
      for(var j=0; j < this.keyValuePairs.length; j++) {
            a[j] = this.keyValuePairs[j].split("=")[0];
            }
      return a;
      }
this.getLength = function() { return this.keyValuePairs.length; }

}
 // Query string for value
function qS(key){return unescape(page.getValue(key));}

function onLoadF(){
      page = new parseQ(window.location.search);
      displayWelcome();
      }

function displayWelcome(){
      var w1_=qS('w1');
      var w2_=qS('w2');
      var V_=qS('select');
      if(V_!='false'){
            if(V_=="INT") out_="You have arrived from link A";
            else if(V_=="NAM") out_="You have arrived from link B";
            else out_="Unknown: "+V_;
            }
      else
            {return false;}
      document.write(out_);
      if(w1_!='false') document.write("<BR>Your first word:  "+w1_)
      if(w2_!='false') document.write("<BR>Your second word: "+w2_)
      }

</script>
<body onload='onLoadF();');">

<!-- FORM below can/should appear on separate page, which would submit to this page to parse the FORM data.
     This form is here instead just for a simpler demo -->

<FORM action="p9.htm" name=f>
Word 1 <input name='w1'>
<P>
Word 2 <input name='w2'>
<input type=submit Value="Go!">
<select name="select">
    <option value="INT" selected>Option A</option>
    <option value="NAM">Option B</option>
  </select>
</FORM>

</body>
</html>
0
 

Author Comment

by:JoHarris
ID: 16976425
That's smashing thanks - the third reply was slightly more help in that I could see how it worked.  I'm sure your answer was great too jagadeesh but I'm just a bit simple for it!

The help is much appreciated!
0
 
LVL 10

Expert Comment

by:jagadeesh_motamarri
ID: 16976472
:-)
Thank You,
___Jags.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

876 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