473,768 Members | 5,794 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

onChange of listbox to update link?

I have a PHP page that generates a list box with several options in it.

I would like to have a "view" link next to the list box. When the user
changes the contents of the list box, I would like the view link to
update to point to the image representing that selection. So for
example, if the list box held names of images I would want the view link
to always point at the correct image.

To further complicate this matter, the selections of the listbox are in
PHP variables.

I basically have little to no experience with javascript and could use
some guidance in figuring this out.

Thanks.

Jason
jl*****@NoSpamA ustin.rr.com
Jul 23 '05 #1
1 9710
John Doe wrote:
I have a PHP page that generates a list box with several options in it.

I would like to have a "view" link next to the list box. When the user
changes the contents of the list box, I would like the view link to
update to point to the image representing that selection. So for
example, if the list box held names of images I would want the view link
to always point at the correct image.
You just need to change the href of the link behind the 'view'
button/link.

To further complicate this matter, the selections of the listbox are in
PHP variables.
Browsers do not understand PHP. You must write HTML so that the
JavaScript can use the values. You could put the link values
into the document in a meta tag, or as an array in a script
element, but I think using the value attribute of an option is
better.

I basically have little to no experience with javascript and could use
some guidance in figuring this out.


Here is a script that offers two solutions - the first I think
is better. If the user has JavaScript enabled, they click the
'View' button and are taken to the new location (image,
whatever). If not, the selected URL is passed to the server,
where you can return the new link and send them to the new link
anyway.

The second is more what you have asked for, but if JS is not
enabled, then the link should by default go somewhere that
explains why the link doesn't work.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Select </title>
<meta http-equiv="Content-Type"
content="text/html; charset=ISO-8859-1">
<script type="text/javascript">

function gotoLink(s){
var newLink = s[s.selectedIndex].value;

// If no selection made
if (newLink == '') {
alert("Please select a destination");
return false;
}

// If a selection has been made, go there
document.locati on = newLink;
}

function updateLink(s,p) {
var a;
if (document.getEl ementById){
a = document.getEle mentById(p);
} else if (document.all){
a = document.all[p];
}

// Update the link based on selection
a.href = s[s.selectedIndex].value;
a.innerHTML = s[s.selectedIndex].text;
}

</script>
</head>
<body>
<!-- uses a form. If JS enabled, takes user to link
when 'view' button clicked. If JS not enabled,
form submitted to server, can handle new link there.
-->
<form action="" onsubmit="
gotoLink(this.l inkSelect);
return false; // If JS enabled, stops form submission;
">
<table>
<tr><td>
<select name="linkSelec t">
<option value="" selected>Pick a destination</option>
<option value="http://www.google.com" >Google</option>
<option value="http://www.yahoo.com"> Yahoo</option>
</select>
</td><td>
<input type="submit" value="View">
</td></tr>
</table>
</form>

<!-- Changes the href of 'view' link onchange. Does not use
a form
-->
<table><tr><t d>
<select onchange="updat eLink(this,'pic Link');">
<option value="" selected>Pick a destination</option>
<option value="http://www.google.com" >Google</option>
<option value="http://www.yahoo.com"> Yahoo</option>
</select>
</td><td>
<a id="picLink"
href="enableJS. html">Select a destination</a><br>
</td></tr>
</table>
</body>
</html>


--
Rob
Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
5760
by: Lee Mundie | last post by:
Hi there, Simple problem here but can't seem to fix it! Okay, I have a select list from which people choose avatars... the list is option values ie. <option>Worm</option> <option>Frog</option> etc etc and is in an include file... where the word i.e. worm sources the image ..images/worm.gif - simple so far...
3
1637
by: NewmanBT | last post by:
As you can see from the code below, several textboxes will be dynamically created and each will be tied to an org. The ChangeComment function should allow for an update to the database whenever the value of the associated textbox changes. However, I'm having trouble associating the textbox to the org. strOrg is a global variable which changes throughout the runtime. How do I capture its value at each stage a textbox is created so that...
2
3330
by: Alpha | last post by:
How do I change the selected item in a listbox according to a Combox's selected item on the same form? The Combox is from a different table in the same dataset as the Listbox uses. Combox's ValueMember is a ID that is a column in the table that the listbox uses. Is there a way to link these 2's relation so that when the user changes the selection in the Combox the list box would automacticall changes to reflect the items that's linked to...
3
8169
by: James Radke | last post by:
Hello, I was curious, is it possible to create drag and drop interface from listbox to listbox on a webform application (i.e. vb.net)? Basically the application would need to load multiple listboxes with values from a database, allow the user to drag and drop from a listbox to a different listbox and would 'move' the item and update the database accordingly? If so, would anyone have any examples of how to do this?
6
9971
by: Mark | last post by:
Hello. I have a listbox whose rowsource is set to a saved query (call it "qry_customer_list.") When I add customers to my database, I call the listbox Requery method so that the listbox will display the customers that I added. Unfortunately, the listbox display does not change. If I close the form and reload it, then the listbox will show the new customers. Any suggestions on how to fix this?
3
4299
by: Kevin Walzer | last post by:
I'm trying to set the active item in a Tkinter listbox to my application's currently-defined default font. Here's how I get the fonts loaded into the listbox: self.fonts=list(tkFont.families()) self.fonts.sort() for item in self.fonts: self.fontlist.insert(END, item) #self.fontlist is the
1
10951
by: sklett | last post by:
I've setup the simplest of tests; A form with a ListBox and a Button. The ListBox is bound to a List<string>. When you click the Button, a new string is added to the list. I can't for the life of me get the ListBox to update when new items are added to it's DataSource! <code> List<stringdateTimeStringList = new List<string>(); private void button1_Click(object sender, EventArgs e) {
3
2489
by: deejayquai | last post by:
Hello Simple one this I guess, but I'm quite stuck at the moment. I would like to update the records displayed in my listbox (lstStudents) using criteria selected from my combo (cboForm) in a form. My basic code is:
0
9575
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
9960
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9842
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7384
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6656
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5280
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5425
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3931
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2808
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.