Current location: Hot Scripts Forums » General Web Coding » JavaScript » how to use current value


how to use current value

Reply
  #1 (permalink)  
Old 02-25-09, 05:35 AM
jonnekke jonnekke is offline
Code Guru
 
Join Date: Oct 2005
Location: holland!
Posts: 706
Thanks: 0
Thanked 0 Times in 0 Posts
how to use current value

Hi there...

I got a form on my site with a select in it:

HTML Code:
<select name="venster4" size="1">
<option value="image1">Image One</option>
<option value="image2">Image Two</option>
<option value="image3">Image Three</option>
<option value="image4">Image Four</option>
<option value="image5">Image Five</option>
<option value="image6">Image Six</option>
</select>
next to this select box I want to create a link to preview the current
selected image in the select. This should open a pop-up and show
the selected image. So the value of the option should be passed to a link
and opened in the pop-up. This should all be happening before the form
is submitted.

Who can help me out here..

_j
Reply With Quote
  #2 (permalink)  
Old 02-25-09, 06:50 AM
Yeroon's Avatar
Yeroon Yeroon is offline
Code Master
 
Join Date: Aug 2007
Location: Netherlands, Nijmegen
Posts: 850
Thanks: 2
Thanked 20 Times in 20 Posts
This should work if you put the image urls in the value of the select oiptions:

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<script type="text/javascript">
function setPopUp(sel)
{

	for(var i = 0; i < sel.options.length;i++){
		if(sel.options[i].selected && sel.options[i] != "0"){
			var myDiv = document.getElementById("divLink");

			myDiv.innerHTML = myDiv.htmlContent = "<a href='#' onclick='javascript:window.open(\"" + sel.options[i].value + "\");'>open preview</a>";
		}
	}

}
</script>

</head>

<body class="mybody">
<form action="post">
<select name="venster4" size="1" onchange="setPopUp(this);">
<option value="0">Select one</option>
<option value="images/image1.jpg">Image One</option>
<option value="images/image2.jpg">Image Two</option>
<option value="images/image3.jpg">Image Three</option>
<option value="images/image4.jpg">Image Four</option>
<option value="images/image5.jpg">Image Five</option>
<option value="images/image6.jpg">Image Six</option>
</select>
<div id="divLink"></div>
</form>

</body>
</html>
__________________
Feel free to thank people if they help you by clicking thanks at a post.
=================================
Make it idiot proof and someone will make a better idiot.
=================================
Realise the impotence of proof reading everything you publish
Reply With Quote
  #3 (permalink)  
Old 02-25-09, 06:58 AM
jonnekke jonnekke is offline
Code Guru
 
Join Date: Oct 2005
Location: holland!
Posts: 706
Thanks: 0
Thanked 0 Times in 0 Posts
this comes very close to what I want

exept the fact that there is always one of the options selected.
so there will be no value=0 option.
So it needs to set the preview link also when the page is loaded.

_j
Reply With Quote
  #4 (permalink)  
Old 02-25-09, 07:06 AM
Yeroon's Avatar
Yeroon Yeroon is offline
Code Master
 
Join Date: Aug 2007
Location: Netherlands, Nijmegen
Posts: 850
Thanks: 2
Thanked 20 Times in 20 Posts
Add the id tag to your select:

Code:
<select id="venster4" name="venster4" size="1" onchange="setPopUp(this);">
And add this to your body element:

Code:
<body onload="setPopUp(document.getElementById('venster4'));">
__________________
Feel free to thank people if they help you by clicking thanks at a post.
=================================
Make it idiot proof and someone will make a better idiot.
=================================
Realise the impotence of proof reading everything you publish
Reply With Quote
  #5 (permalink)  
Old 02-25-09, 07:29 AM
jonnekke jonnekke is offline
Code Guru
 
Join Date: Oct 2005
Location: holland!
Posts: 706
Thanks: 0
Thanked 0 Times in 0 Posts
great! it works... thnx a lot..

there is one small layout issue.. I tried to add width, height and scrollbar to the
javascript.. but this isn't working like this:

HTML Code:
onclick='javascript:window.open(\"../../images/banner/" + sel.options[i].value + "\",\"location=0,status=0,scrollbars=1,width=200,height=100\");'
you got any idea why?...
seems like normaal javascript to me..

_j
Reply With Quote
  #6 (permalink)  
Old 02-25-09, 07:45 AM
Yeroon's Avatar
Yeroon Yeroon is offline
Code Master
 
Join Date: Aug 2007
Location: Netherlands, Nijmegen
Posts: 850
Thanks: 2
Thanked 20 Times in 20 Posts
You added the width height properties to the popup windowname.

Change it to:

Code:
onclick='javascript:window.open(\"../../images/banner/" + sel.options[i].value + "\",\"mypopupwindow\",\"location=0,status=0,scrollbars=1,width=200,height=100\");'
__________________
Feel free to thank people if they help you by clicking thanks at a post.
=================================
Make it idiot proof and someone will make a better idiot.
=================================
Realise the impotence of proof reading everything you publish
Reply With Quote
  #7 (permalink)  
Old 03-02-09, 07:57 AM
Hsekhar Hsekhar is offline
Newbie Coder
 
Join Date: Feb 2009
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
This is what I have been looking for myself, Thanks for the solution. I think I need to improve a lot in Javascript.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
A script to scrape a current image and store it in a db, always using the same name? wolfdogg Script Requests 1 12-08-06 01:10 AM
select current users country aish JavaScript 0 09-20-05 03:10 AM
Updating current money spent in a form with checkboxes. . . Spreegem JavaScript 4 07-13-05 09:10 PM
Current Date in SQL Abulafia PHP 2 09-20-04 07:46 AM
Compare Data From Current and Previous Records Cameron Roat PHP 9 07-25-04 11:11 AM


All times are GMT -5. The time now is 11:46 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.