Rewaya
asked on
get datalist selected item javascript
hi
i have datalist in aspx page and i want to get selected item value using java script at SetSelectedItemList() function
how can i do that ??
i have datalist in aspx page and i want to get selected item value using java script at SetSelectedItemList() function
how can i do that ??
<td>
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Bind("itemPath") %>'
Text='<%# Bind("itemName") %> ' onclick="SetSelectedItemList();"></asp:HyperLink>
</td>
ASKER
value of var thisValue = thisItem.value; is undefined :(
var thisValue = thisItem.text;
Which value do you want to get back for the link? I don't see a simple "value" property. Are you trying to get back the "Text"?
Let's try this inside the function and see if you get back the Text value:
Let's try this inside the function and see if you get back the Text value:
alert(this); // should show [object]
var thisValue = thisItem.Text;
alert(thisValue)
ASKER
still undefined
at first alert(this); // should show [object Show [Object Window]
second alert(thisValue) Show undefined
at first alert(this); // should show [object Show [Object Window]
second alert(thisValue) Show undefined
can you post HTML code here??
ASKER
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DirectoreyFiles.aspx.cs"
Inherits="DirectoreyFiles" %>
<!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 runat="server">
<title></title>
<style type="text/css">
.style4
{
width: 670px;
}
.style3
{
width: 100%;
}
.style5
{
width: 70px;
}
.style6
{
width: 289px;
}
.style1
{
width: 100%;
height: 119px;
}
</style>
<script type="text/javascript">
var path;
function CreatNewFolder() {
var filename = prompt("Please write folder Name", "NewFolder");
try {
var myObject, newfolder;
myObject = new ActiveXObject("Scripting.FileSystemObject");
path = decodeURIComponent(path);
newfolder = myObject.CreateFolder(path + "//" + filename);
alert("Folder created at " + path + "//" + filename);
}
catch (err) {
alert(err);
}
}
function SetPath() {
if (location.search != "") {
path = window.location.search;
var parms = path.split('=');
path = "<%=AppDomain.CurrentDomain.BaseDirectory.ToString().Replace(@"\", "/")%>" + parms[1];
}
}
function SetSelectedItemList(thisItem)
{
var querystring = window.location.search;
alert("Folder created at "+querystring);
//this.opener.document.getElementById("testx").value="xx";
//((HiddenField)DataList1.SelectedItem.FindControl("hdnID")).Value
alert(this); // should show [object]
var thisValue = thisItem.Text;
alert(thisValue)
parent.hello(thisValue);
}
// function alertMe(hi) {
// alert(hi);
// }
// function SetFolderPath(pathvalue) {
// path = pathvalue;
// alert(decodeURIComponent(path));
// var baseDirectory = "<%=AppDomain.CurrentDomain.BaseDirectory.ToString().Replace(@"\", "/")%>";
// alert(path);
// alert(baseDirectory);
// }
</script>
</head>
<body onload="SetPath();">
<form id="form1" runat="server">
<div>
<table class="style1">
<tr>
<td valign="top" height="100%" class="style4" colspan="4">
<asp:DataList ID="DataList1" runat="server" Width="794px" BorderStyle="Solid" RepeatColumns="3"
RepeatDirection="Horizontal" RepeatLayout="Flow">
<ItemTemplate>
<table class="style3">
<tr>
<td>
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Bind("itemPath") %>'
Text='<%# Bind("itemName") %> ' onclick="SetSelectedItemList(this);"></asp:HyperLink>
</td>
</tr>
<tr>
<td>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
</td>
</tr>
<tr>
<td valign="top" height="100%" class="style5">
<asp:Button ID="Button_CreateNewFolder" runat="server" Style="width: 100%" OnClientClick="CreatNewFolder();"
Text="Create New Folder" OnClick="Button_CreateNewFolder_Click" Width="70px" />
</td>
<td valign="top" height="100%" class="style6">
<asp:Label ID="Label_UploadFile" runat="server" Style="text-align: center" Text="Upload a new file in this folder"></asp:Label>
</td>
<td valign="top" height="100%" class="style4">
<asp:FileUpload ID="FileUpload" runat="server" />
<br />
<asp:Label ID="Label_StatusLabel" runat="server" Text="Upload status: "></asp:Label>
</td>
<td valign="top" height="100%" class="style4">
<asp:Button ID="Button_Upload" runat="server" Text="UpLoad" Height="26px" OnClick="Button_Upload_Click" />
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
at 63 line you put alert(this); // should show [object]
put thisItem
alert(thisItem); // should show [object]
var thisValue = thisItem.Text;
put thisItem
alert(thisItem); // should show [object]
var thisValue = thisItem.Text;
check this
<script>
function SetSelectedItemList(thisIt em)
{
alert(thisItem); // should show [object]
var thisValue = thisItem.Text;
alert(thisValue)
}
</script>
</HEAD>
<BODY>
<input type='button' Text='sss' value='aaa' onclick='SetSelectedItemLi st(this)'>
</BODY>
</HTML>
<script>
function SetSelectedItemList(thisIt
{
alert(thisItem); // should show [object]
var thisValue = thisItem.Text;
alert(thisValue)
}
</script>
</HEAD>
<BODY>
<input type='button' Text='sss' value='aaa' onclick='SetSelectedItemLi
</BODY>
</HTML>
Thanks chaituu for pitching in. We'll get to the bottom of this.
I think the asp tag is generating different tags than we're expecting.
Please see what this does:
I think the asp tag is generating different tags than we're expecting.
Please see what this does:
function SetSelectedItemList(thisItem)
{
var thisValue = thisItem.href;
alert(thisValue);
}
ASKER
still undefined for each
var thisValue = thisItem.href;
var thisValue = thisItem.Text;
var thisValue = thisItem.href;
var thisValue = thisItem.Text;
Just a thought. When you look at your web page in a browser and "View Source", does it still show "asp" tags or have they been expanded into html <a> tags? We may have better luck if we can see the "source" as seen by the browser rather than the raw source file.
Please paste the results of the View Source window here so we can see it, too. Thanks.
Please paste the results of the View Source window here so we can see it, too. Thanks.
paste your view source of html code...take right click of the page and copy the source paste it here.
ASKER
<!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><title>
</title>
<style type="text/css">
.style4
{
width: 670px;
}
.style3
{
width: 100%;
}
.style5
{
width: 70px;
}
.style6
{
width: 289px;
}
.style1
{
width: 100%;
height: 119px;
}
</style>
<script type="text/javascript">
var path;
function CreatNewFolder() {
var filename = prompt("Please write folder Name", "NewFolder");
try {
var myObject, newfolder;
myObject = new ActiveXObject("Scripting.FileSystemObject");
path = decodeURIComponent(path);
newfolder = myObject.CreateFolder(path + "//" + filename);
alert("Folder created at " + path + "//" + filename);
}
catch (err) {
alert(err);
}
}
function SetPath() {
if (location.search != "") {
path = window.location.search;
var parms = path.split('=');
path = "E:/Rabtah Project/Study CMS Code/WebSite Study/UploadFiles/" + parms[1];
}
}
function SetSelectedItemList(thisItem)
{
var querystring = window.location.search;
// alert("Folder created at "+querystring);
thisItem = decodeURIComponent(thisItem);
// alert(thisItem); // should show [object]
var thisValue = thisItem.href;
alert (thisItem);
alert(thisValue)
parent.hello(thisItem);
}
// function alertMe(hi) {
// alert(hi);
// }
// function SetFolderPath(pathvalue) {
// path = pathvalue;
// alert(decodeURIComponent(path));
// var baseDirectory = "E:/Rabtah Project/Study CMS Code/WebSite Study/UploadFiles/";
// alert(path);
// alert(baseDirectory);
// }
</script>
</head>
<body onload="SetPath();">
<form name="form1" method="post" action="DirectoreyFiles.aspx?DirectoryName=Upload%2fImage%2fmarwaa&Item_ParentCode=6&Item_Order=3" id="form1" enctype="multipart/form-data">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMjEzMDcxODgwNw9kFgICAw8WAh4HZW5jdHlwZQUTbXVsdGlwYXJ0L2Zvcm0tZGF0YRYCAgEPPCsACQEADxYEHghEYXRhS2V5cxYAHgtfIUl0ZW1Db3VudAIIZBYQZg9kFgICAQ8PFgQeC05hdmlnYXRlVXJsBVVFOi9SYWJ0YWggUHJvamVjdC9TdHVkeSBDTVMgQ29kZS9XZWJTaXRlIFN0dWR5L1VwbG9hZEZpbGVzL1VwbG9hZC9JbWFnZS9tYXJ3YWFcaG9waG9wHgRUZXh0BQZob3Bob3BkZAIBD2QWAgIBDw8WBB8DBVVFOi9SYWJ0YWggUHJvamVjdC9TdHVkeSBDTVMgQ29kZS9XZWJTaXRlIFN0dWR5L1VwbG9hZEZpbGVzL1VwbG9hZC9JbWFnZS9tYXJ3YWFca2pramtqHwQFBmtqa2pramRkAgIPZBYCAgEPDxYEHwMFU0U6L1JhYnRhaCBQcm9qZ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RDYkUoT/rulaawhi2EmEPU8w0npFG" />
</div>
<div>
<table class="style1">
<tr>
<td valign="top" height="100%" class="style4" colspan="4">
<span id="DataList1" style="display:inline-block;border-style:Solid;width:794px;"><span>
<table class="style3">
<tr>
<td>
<a id="DataList1_ctl00_HyperLink1" onclick="SetSelectedItemList(this);" href="E:/Rabtah%20Project/Study%20CMS%20Code/WebSite%20Study/UploadFiles/Upload/Image/marwaa\hophop">hophop</a>
</td>
</tr>
<tr>
<td>
</td>
</tr>
</table>
</span><span>
<table class="style3">
<tr>
<td>
<a id="DataList1_ctl01_HyperLink1" onclick="SetSelectedItemList(this);" href="E:/Rabtah%20Project/Study%20CMS%20Code/WebSite%20Study/UploadFiles/Upload/Image/marwaa\kjkjkj">kjkjkj</a>
</td>
</tr>
<tr>
<td>
</td>
</tr>
</table>
</span><span>
<table class="style3">
<tr>
<td>
<a id="DataList1_ctl02_HyperLink1" onclick="SetSelectedItemList(this);" href="E:/Rabtah%20Project/Study%20CMS%20Code/WebSite%20Study/UploadFiles/Upload/Image/marwaa\null">null</a>
</td>
</tr>
<tr>
<td>
</td>
</tr>
</table>
</span><br /><span>
<table class="style3">
<tr>
<td>
<a id="DataList1_ctl03_HyperLink1" onclick="SetSelectedItemList(this);" href="E:/Rabtah%20Project/Study%20CMS%20Code/WebSite%20Study/UploadFiles/Upload/Image/marwaa\yarab">yarab</a>
</td>
</tr>
<tr>
<td>
</td>
</tr>
</table>
</span><span>
<table class="style3">
<tr>
<td>
<a id="DataList1_ctl04_HyperLink1" onclick="SetSelectedItemList(this);" href="E:/Rabtah%20Project/Study%20CMS%20Code/WebSite%20Study/UploadFiles/Upload/Image/marwaa\4b98762273.gif">4b98762273.gif</a>
</td>
</tr>
<tr>
<td>
</td>
</tr>
</table>
</span><span>
<table class="style3">
<tr>
<td>
<a id="DataList1_ctl05_HyperLink1" onclick="SetSelectedItemList(this);" href="E:/Rabtah%20Project/Study%20CMS%20Code/WebSite%20Study/UploadFiles/Upload/Image/marwaa\9.jpg">9.jpg</a>
</td>
</tr>
<tr>
<td>
</td>
</tr>
</table>
</span><br /><span>
<table class="style3">
<tr>
<td>
<a id="DataList1_ctl06_HyperLink1" onclick="SetSelectedItemList(this);" href="E:/Rabtah%20Project/Study%20CMS%20Code/WebSite%20Study/UploadFiles/Upload/Image/marwaa\hophop_2__12-06-09_2015.jpg">hophop_2__12-06-09_2015.jpg</a>
</td>
</tr>
<tr>
<td>
</td>
</tr>
</table>
</span><span>
<table class="style3">
<tr>
<td>
<a id="DataList1_ctl07_HyperLink1" onclick="SetSelectedItemList(this);" href="E:/Rabtah%20Project/Study%20CMS%20Code/WebSite%20Study/UploadFiles/Upload/Image/marwaa\Thumbs.db">Thumbs.db</a>
</td>
</tr>
<tr>
<td>
</td>
</tr>
</table>
</span><br /></span>
</td>
</tr>
<tr>
<td valign="top" height="100%" class="style5">
<input type="submit" name="Button_CreateNewFolder" value="Create New Folder" onclick="CreatNewFolder();" id="Button_CreateNewFolder" style="width:70px;width: 100%" />
</td>
<td valign="top" height="100%" class="style6">
<span id="Label_UploadFile" style="text-align: center">Upload a new file in this folder</span>
</td>
<td valign="top" height="100%" class="style4">
<input type="file" name="FileUpload" id="FileUpload" />
<br />
<span id="Label_StatusLabel">Upload status: </span>
</td>
<td valign="top" height="100%" class="style4">
<input type="submit" name="Button_Upload" value="UpLoad" id="Button_Upload" style="height:26px;" />
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
u didnt write decodeURIComponent method..
thisItem = decodeURIComponent(thisIte m);
thisItem = decodeURIComponent(thisIte
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ok now works Thanks
but little question how can i remove %20 and / backslash from var thisValue = thisItem.href;
but little question how can i remove %20 and / backslash from var thisValue = thisItem.href;
Not sure if you mean slash or backslash - this does both
<script>
var foo="abc%20def/gh\\ij"
alert(foo)
foo = foo.replace("%20","")
alert(foo)
foo = foo.replace("/","")
alert(foo)
foo = foo.replace("\\","")
alert(foo)
</script>
I think this is what you really want, though.. Turn the path into a DOS filename?
<script>
var thisValue="E:/Rabtah%20Project/Study%20CMS%20Code/WebSite%20Study/UploadFiles/Upload/Image/marwaa\\hophop"
alert(thisValue)
thisValue = thisValue.replace(/\%20/g," ")
thisValue = thisValue.replace(/\//g,"\\")
alert(thisValue)
</script>
ASKER
var thisValue = thisItem.href;
thisValue = decodeURIComponent(thisVal ue);
thisValue = thisValue.replace("%20"," ");
thisValue = thisValue.replace("file:// /","");
E:/Rabtah Project/Study%20CMS%20Code /WebSite%2 0Study/Upl oadFiles/U pload/Imag e/New%20Fo lder/b3b3. txt
still exist %20
and also this not solve problem
alert(thisValue)
thisValue = thisValue.replace(/\%20/g, " ")
thisValue = thisValue.replace(/\//g,"\ \")
alert(thisValue)
thisValue = decodeURIComponent(thisVal
thisValue = thisValue.replace("%20"," ");
thisValue = thisValue.replace("file://
E:/Rabtah Project/Study%20CMS%20Code
still exist %20
and also this not solve problem
alert(thisValue)
thisValue = thisValue.replace(/\%20/g,
thisValue = thisValue.replace(/\//g,"\
alert(thisValue)
Ok. Instead of giving you small fragments of code, this is what I think the whole SetSelectedItemList function should look like. Please try it just like this. If it still doesn't work, please post what the output of the "alert" boxes showed.
PS. Rewaya: In my first attempt I made a mistake using a quoted string as the first argument to the replace function. It only replaces the first occurrence unless you use a regexp with the /g flag.
function SetSelectedItemList(thisItem)
{
var thisValue = thisItem.href;
alert(thisValue)
thisValue = thisValue.replace(/\%20/g," ")
thisValue = thisValue.replace(/\//g,"\\")
alert(thisValue)
parent.hello(thisValue);
}
PS. Rewaya: In my first attempt I made a mistake using a quoted string as the first argument to the replace function. It only replaces the first occurrence unless you use a regexp with the /g flag.
ASKER
Thnx very muchhhh
ASKER
still
file:\\\E:\Rabtah%2520Proj ect\Study% 2520CMS%25 20Code\Web Site%2520S tudy\Uploa dFiles\Upl oad\Image\ marwaa\4b9 8762273.gi f
file:\\\E:\Rabtah%2520Proj
Ok. With that info, this should do it:
function SetSelectedItemList(thisItem)
{
var thisValue = thisItem.href;
alert(thisValue)
thisValue = thisValue.replace(/^file\:\\*/ig,"")
thisValue = thisValue.replace(/\%2520/g," ")
thisValue = thisValue.replace(/\%20/g," ")
thisValue = thisValue.replace(/\//g,"\\")
alert(thisValue)
parent.hello(thisValue);
}
ASKER
yessss now solved thank you very much :)))
chaituu, enjoyed working with you. Good teamwork.
me too..good luck..
ASKER
chaituu and sjklein42 enjoyed learning from you
Open in new window