Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Process selection/display content 1

Status
Not open for further replies.

mark39

Technical User
Apr 19, 2007
4
CA
I'll try to be as short as possible with this..
I have built a local business search site for my employer and I wanted to create a sort of 'targeted ads' function on the page. I would like to be able to select from a dropdown list and display an ad in a different iframe based on the selection. This select box is also sent to my php search script so I can't use any values for the options other than duplicate the displayed options as it messes up my search results i.e.
<option value="example">example</option> (i could use this)

I have just started to learn javascript and I'm under the impression that there needs to be an 'onChange' event associated with the select box, and I'm assuming I will have to create 'if' statements for all the variables in the dropdown list....sort of:eek:nChange/process variable from select box/IF variable=??? get url/ target=iframe.

I'm probably way off in my thinking/logic of how this should work, but any help would be great!!

I'm just not sure where to start.

Thanks, Mark39
 
I'd use something like this:
Code:
<select onchange="document.frames['targetframenamehere'].src = '[URL unfurl="true"]http://www.'[/URL] + this.options[this.selectedIndex].value">
  <option value="google.com">Google</option>
  <option value="thisurl.com/page1.htm">Page 1</option>
</select>

This will store the URL values in the option value and you won't have to create a separate JS function to handle what you want to do.

You can create an array of URLs and use a function to do the same thing like you initially were thinking of, or hard code a whole list of if/if else/else statements if you like.

Lee
 
Thanks a bunch Lee,
At least I know my logic wasn't too far off. I think I'll have to code out the if/else statements because the option values will mess with my search.php that reads the selection and any associated values when it's submitted.

If I go the if/else route, do I reference the target frame at the select box as you have done above or in the actual function itself?

Mark
 
Why don't you put the URLs in an array at the top of the page, then use
Code:
<script type="text/javascript">
var URLs = ['google.com', 'thissite.com/page1.htm'];
</script>

<select onchange="document.frames['targetframenamehere'].src = '[URL unfurl="true"]http://www.'[/URL] + URLs[this.selectedIndex]">
  <option value="Google">Google</option>
  <option value="Page 1">Page 1</option>
</select>

That would still allow you to pass select's value to the next page.

Lee
 
Trollacious,

I could'nt get your example to work for me whatever I tried, but I was doing a bit more studying and came up with this:

<script>
function changeAd(){
var currentSel = document.getElementById("selection");
var duff = document.getElementById("duff");
var well = document.getElementById("well");

if (currentSel == "Alarm Systems and Monitoring" && duff.checked == true);{
document.getElementById("adbox").src = "ads/ad5.jpg"};

}
</script>

I have an onClick event to trigger this attached to the submit button.


This will load my iframe(adbox) with an ad but it seems to ignore the 'if' statement. (displays ad regardless of selection) I also have 2 checkboxes (duff & well) and wanted to add them to the mix. I'm not sure about my syntax but they don't work either. Seems the only thing being read is the: document.getElementById("adbox").src = "ads/ad5.jpg"


Any ideas ??????anyone?
 
Code:
 if (currentSel == "Alarm Systems and Monitoring" && duff.checked == true)[s][!];[/!][/s]{

[monkey][snake] <.
 
Monksnake - You are da man/woman/person!!!!!!!!

Thankyou very much :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top