Search Results

Search found 24399 results on 976 pages for 'datatable select'.

Page 11/976 | < Previous Page | 7 8 9 10 11 12 13 14 15 16 17 18  | Next Page >

  • Create form select from object containing values

    - by marks34
    I have such an object : var options = {1: 'Running', 2: 'Falling', 3: 'Collapsing wall', 4: (...)}; I'd like to create form's select element with ooptions taken from this object, so something like that (code I tried which is not working, but you can get the idea) : html = '<form action="" ><select name="block-action"><option>-------</option>'; for(k in obj){ html += '<option value="'+k+'">'+obj[k]+'</option>' } html += '</select></form>'

    Read the article

  • Dojo Select widget validation style

    - by jamstooks
    Many dojo form widgets, like DateTextBox will style themselves in red (claro theme) with an "!" to indicate that the field isn't valid after focus. I can't seem to get this type of styling to work with the Select widget. I have the value set to required, but if the user leaves it in the default state, blank, then it remains unstyled. I tried to test this programmatically: wigs = dijit.findWidgets(node); for( i = 0; i < wigs.length; i++ ) { wigs[i].focus(); } This triggers validation on several other widgets and they are styled appropriately, but not he Select widgets. Anyone know how to make it obvious that those select widgets are not validating? Oh, and wigs[i].isValid() is definitely false for those select widgets.

    Read the article

  • How do I select an option using Spring's form:select tag?

    - by Dave
    I'm using Spring 3.1.1.RELEASE. Using the form:select tag, how do I specify which option should be selected? I want the first one to be selected, but when I put <form:select path="parentOrganization"> <form:option value="" label="Select an Org Type or Parent Org" /> <form:options items="${orgTypesWoParents}" itemValue="id" itemLabel="description" /> <form:option value="" label="=======================" /> </form:select> the last one is selected. I want to preserve the order of how everything is displayed, which is why I've arranged things in this way.

    Read the article

  • C# Linq Select Problem in Method Chain.

    - by Gnought
    Note that the _src inherit IQueryable<U> and V inherit new(); I wrote the following statement, there is no syntax error. IQueryable<V> a = from s in _src where (s.Right - 1 == s.Left) select new V(); But if i re-wrote it as follows, the Visual Studio editor complains an error in the "Select" IQueryable<V> d = _src.Where(s => s.Right - 1 == s.Left).Select(s=> new V()); The Error is: The type arguments cannot be inferred from the usage. Try specifying the type arguments explicitly. Candidates are: System.Collections.Generic.IEnumerable<V> Select<U,V>(this System.Collections.Generic.IEnumerable<U>, System.Func<U,V>) (in class Enumerable) System.Linq.IQueryable<V> Select<U,V>(this System.Linq.IQueryable<U>, System.Linq.Expressions.Expression<System.Func<U,V>>) (in class Queryable) Could anyone explain this phenomenon, and what the solution is to fix the error?

    Read the article

  • What is the correct date format for a Date column in YUI DataTable ?

    - by giulio
    I have produced a data table. All the columns are sortable. It has a date in one column which I formatted dd/mm/yyyy hh:mm:ss . This is different from the default format as defined in the doco, but I should be able to define my own format for non-american formats. (See below) The DataTable class provides a set of built-in static functions to format certain well-known types of data. In your Column definition, if you set a Column's formatter to YAHOO.widget.DataTable.formatDate, that function will render data of type Date with the default syntax of "MM/DD/YYYY". If you would like to bypass a built-in formatter in favor of your own, you can point a Column's formatter to a custom function that you define. The table is generated from HTML Markup, so the data is held within "" tags. This gives me some more clues about compatible string dates for javascript: In general, the RecordSet expects to hold data in native JavaScript types. For instance, a date is expected to be a JavaScript Date instance, not a string like "4/26/2005" in order to sort properly. Converting data types as data comes into your RecordSet is enabled through the parser property in the fields array of your DataSource's responseSchema I suspect that the I'm missing something in the date format. So what is an acceptable string date for javascript, that Yui dataTable will recognise, given that I want format it as "dd/mm/yyyy hh:mm:ss" ?

    Read the article

  • How can I add the column data type after adding the column headers to my datatable?

    - by Kevin
    Using the code below (from a console app I've cobbled together), I add seven columns to my datatable. Once this is done, how can I set the data type for each column? For instance, column 1 of the datatable will have the header "ItemNum" and I want to set it to be an Int. I've looked at some examples on thet 'net, but most all of them show creating the column header and column data type at once, like this: loadDT.Columns.Add("ItemNum", typeof(Int)); At this point in my program, the column already has a name. I just want to do something like this (not actual code): loadDT.Column[1].ChangeType(typeof(int)); Here's my code so far (that gives the columns their name): // get column headings for datatable by reading first line of csv file. StreamReader sr = new StreamReader(@"c:\load_forecast.csv"); headers = sr.ReadLine().Split(','); foreach (string header in headers) { loadDT.Columns.Add(header); } Obviously, I'm pretty new at this, but trying very hard to learn. Can someone point me in the right direction? Thanks!

    Read the article

  • Best way to get a single value from a DataTable?

    - by PiersMyers
    I have a number of static classes that contain tables like this: using System; using System.Data; using System.Globalization; public static class TableFoo { private static readonly DataTable ItemTable; static TableFoo() { ItemTable = new DataTable("TableFoo") { Locale = CultureInfo.InvariantCulture }; ItemTable.Columns.Add("Id", typeof(int)); ItemTable.Columns["Id"].Unique = true; ItemTable.Columns.Add("Description", typeof(string)); ItemTable.Columns.Add("Data1", typeof(int)); ItemTable.Columns.Add("Data2", typeof(double)); ItemTable.Rows.Add(0, "Item 1", 1, 1.0); ItemTable.Rows.Add(1, "Item 2", 1, 1.0); ItemTable.Rows.Add(2, "Item 3", 2, 0.75); ItemTable.Rows.Add(3, "Item 4", 4, 0.25); ItemTable.Rows.Add(4, "Item 5", 1, 1.0); } public static DataTable GetItemTable() { return ItemTable; } public static int Data1(int id) { DataRow[] dr = ItemTable.Select("Id = " + id); if (dr.Length == 0) { throw new ArgumentOutOfRangeException("id", "Out of range."); } return (int)dr[0]["Data1"]; } public static double Data2(int id) { DataRow[] dr = ItemTable.Select("Id = " + id); if (dr.Length == 0) { throw new ArgumentOutOfRangeException("id", "Out of range."); } return (double)dr[0]["Data2"]; } } Is there a better way of writing the Data1 or Data2 methods that return a single value from a single row that matches the given id?

    Read the article

  • Delete blank row in dropdownlist or select default value in infopath dropdown

    - by KunaalKapoor
    Regular Dropdown (Pulling from DataSource)1. Double click on dropdown field in the data source.2. Select Fx button for Default value.3. Select Insert field or group.4. Select secondary xml from data source.5. Select “value” and click on ok.For a cascading dropdown:You have to add the rule and follow these steps,1. Rules -> ‘Add’ - > ‘Add Action’.2. Select ‘Set a field value’ option in first dropdown in Action.3. Select your field with help of ‘Select a Field or Group’ option in ‘Field’.4. Select your external data source list value in ‘Value’.This rule you can apply in OnLoad or whenever you will get external data source values.

    Read the article

  • Binding DataTable To GridView, But No Rows In GridViewRowCollection Despite GridView Population?

    - by KSwift87
    Problem: I've coded a GridView in the markup in a page. I have coded a DataTable in the code-behind that takes data from a collection of custom objects. I then bind that DataTable to the GridView. (Specific problem mentioned a couple code-snippets below.) GridView Markup: <asp:GridView ID="gvCart" runat="server" CssClass="pList" AutoGenerateColumns="false" DataKeyNames="ProductID"> <Columns> <asp:BoundField DataField="ProductID" HeaderText="ProductID" /> <asp:BoundField DataField="Name" HeaderText="ProductName" /> <asp:ImageField DataImageUrlField="Thumbnail" HeaderText="Thumbnail"></asp:ImageField> <asp:BoundField DataField="Unit Price" HeaderText="Unit Price" /> <asp:TemplateField HeaderText="Quantity"> <ItemTemplate> <asp:TextBox ID="Quantity" runat="server" Text="<%# Bind('Quantity') %>" Width="25px"></asp:TextBox> </ItemTemplate> </asp:TemplateField> <asp:BoundField DataField="Total Price" HeaderText="Total Price" /> </Columns> </asp:GridView> DataTable Code-Behind: private void View(List<OrderItem> cart) { DataSet ds = new DataSet(); DataTable dt = ds.Tables.Add("Cart"); if (cart != null) { dt.Columns.Add("ProductID"); dt.Columns.Add("Name"); dt.Columns.Add("Thumbnail"); dt.Columns.Add("Unit Price"); dt.Columns.Add("Quantity"); dt.Columns.Add("Total Price"); foreach (OrderItem item in cart) { DataRow dr = dt.NewRow(); dr["ProductID"] = item.productId.ToString(); dr["Name"] = item.productName; dr["Thumbnail"] = ResolveUrl(item.productThumbnail); dr["Unit Price"] = "$" + item.productPrice.ToString(); dr["Quantity"] = item.productQuantity.ToString(); dr["Total Price"] = "$" + (item.productPrice * item.productQuantity).ToString(); dt.Rows.Add(dr); } gvCart.DataSource = dt; gvCart.DataBind(); gvCart.Width = 500; for (int counter = 0; counter < gvCart.Rows.Count; counter++) { gvCart.Rows[counter].Cells.Add(Common.createCell("<a href='cart.aspx?action=update&prodId=" + gvCart.Rows[counter].Cells[0].Text + "'>Update</a><br /><a href='cart.aspx?action='action=remove&prodId=" + gvCart.Rows[counter].Cells[0].Text + "/>Remove</a>")); } } } Error occurs below in the foreach - the GridViewRowCollection is empty! private void Update(string prodId) { List<OrderItem> cart = (List<OrderItem>)Session["cart"]; int uQty = 0; foreach (GridViewRow gvr in gvCart.Rows) { if (gvr.RowType == DataControlRowType.DataRow) { if (gvr.Cells[0].Text == prodId) { uQty = int.Parse(((TextBox)gvr.Cells[4].FindControl("Quantity")).Text); } } } Goal: I'm basically trying to find a way to update the data in my GridView (and more importantly my cart Session object) without having to do everything else I've seen online such as utilizing OnRowUpdate, etc. Could someone please tell me why gvCart.Rows is empty and/or how I could accomplish my goal without utilizing OnRowUpdate, etc.? When I execute this code, the GridView gets populated but for some reason I can't access any of its rows in the code-behind.

    Read the article

  • Sliding & hiding multiple panels in jQuery.

    - by lloydphillips
    I have a table with multiple rows in each row is a select list and based on the selection (when the onchange event is fired) panels appear containing additional data below the row.I currently have code like this: var allPnls = '.inv-dtl-comnts-add,.inv-dtl-comnts-update'; $(document).ready(function(){ hideAll(); //select action change $(".inv-dtl-ddlaction").change(onSelectChange); $(".btn-cancel").click(function(event){ slideAll(); $(".inv-dtl-ddlaction").val('[Select an Action]'); return false; }); }); function onSelectChange(event){ //find out which select item was clicked switch($(this).val()) { case 'View/Add Comment': $(this).closest(".row").children(allPnls).slideUp("fast", function(){ $(this).closest(".row").children(".inv-dtl-comnts-add").slideToggle("fast"); }); break; case 'Change Status': $(this).closest(".row").children(allPnls).slideUp("fast", function(){ $(this).closest(".row").children(".inv-dtl-comnts-update").slideToggle("fast"); }); break; default: //code to be executed if n is different from case 1 and 2 } } function hideAll(){ $(allPnls).hide(); } function slideAll(){ $(allPnls).slideUp("fast"); } So I'm hiding all the panels when the page loads and if a panel is already open I want to slide it shut before reopening the new panel. This works with the postback. With just one panel in the selection it worked great but with two panels the sliding up happens twice (it seems to slide down unopened panels before sliding them back up again). How can I adjust this so that I can get all panels listed in the variable allPnls to slide shut ONLY if they are already open? Is there a better way of sliding the panels shut and then having a callback to have the slideToggle work? Lloyd

    Read the article

  • jQuery - disable selected options

    - by Jeffrey
    Need to disable already selected options in select box using jQuery. I'd like it to grey out like asmselect. Test my example here. //JS $("#theSelect").change(function(){ var value = $("#theSelect option:selected").val(); var theDiv = $(".is" + value); theDiv.slideDown().removeClass("hidden"); }); $("div a.remove").click(function () { $(this).parent().slideUp(function() { $(this).addClass("hidden"); }); }); //HTML <body> <div class="selectContainer"> <select id="theSelect"> <option value="">- Select -</option> <option value="Patient">Patient</option> <option value="Physician">Physician</option> <option value="Nurse">Nurse</option> </select> </div> <div class="hidden isPatient">Patient <a href="#" class="remove" rel="Patient">remove</a></div> <div class="hidden isPhysician">Physician <a href="#" class="remove" rel="Patient">remove</a></div> <div class="hidden isNurse">Nurse <a href="#" class="remove" rel="Patient">remove</a></div> </body>

    Read the article

  • problem with select boxes - second options based on first selection

    - by Charles Marsh
    Hello All, I just posted a question about opening in a new window but if I use window.location it doesn't work?? is there a problem with my javascript? <script type="text/javascript"> function setOptions(chosen){ var selbox = document.formName.table; selbox.options.length = 0; if (chosen == " ") { selbox.options[selbox.options.length] = new Option('No diploma selected',' '); } if (chosen == "1") { selbox.options[selbox.options.length] = new Option('first choice - option one','http://www.pitman-training.com'); selbox.options[selbox.options.length] = new Option('first choice - option two','onetwo'); } if (chosen == "2") { selbox.options[selbox.options.length] = new Option('second choice - option one','twoone'); selbox.options[selbox.options.length] = new Option('second choice - option two','twotwo'); selbox.options[selbox.options.length] = new Option('second choice - option three','twothree'); selbox.options[selbox.options.length] = new Option('second choice - option four','twofour'); } if (chosen == "3") { selbox.options[selbox.options.length] = new Option('third choice - option one','threeone'); selbox.options[selbox.options.length] = new Option('third choice - option two','threetwo'); } } </script> Its a little messy I know... <form name="formName" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <select name="optone" size="1" onchange="setOptions(document.formName.optone.options[document.formName.optone.selectedIndex].value);"> <option value=" " selected="selected">Please select a diploma</option> <option value="1">First Choice</option> <option value="2">Second Choice</option> <option value="3">Third Choice</option> </select> <select name="table" size="1" > <option value=" " selected="selected">No diploma selected</option> </select> <input type="submit" onclick="ob=this.form.table;window.location(ob.options[ob.selectedIndex].value)"/> </form> to be honest I'm not happy with this anyway I want a way to hide the Submit button until the second selected box has been selected...but I'm no java expert! Can anyone point me in the right direction?

    Read the article

  • How to convert List to Datatable in vb.net

    - by Samir R. Bhogayta
    Public Function ConvertToDataTable(Of T)(ByVal list As IList(Of T)) As DataTable        Dim table As New DataTable()        Dim fields() As FieldInfo = GetType(T).GetFields()        For Each field As FieldInfo In fields            table.Columns.Add(field.Name, field.FieldType)        Next        For Each item As T In list            Dim row As DataRow = table.NewRow()            For Each field As FieldInfo In fields                row(field.Name) = field.GetValue(item)            Next            table.Rows.Add(row)        Next        Return table    End Function

    Read the article

  • What is it about DataTable Column Names with dots that makes them unsuitable for WPF's DataGrid cont

    - by Tom Ritter
    Run this, and be confused: <Window x:Class="Fucking_Data_Grids.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"> <StackPanel> <DataGrid Name="r1" ItemsSource="{Binding Path=.}"> </DataGrid> <DataGrid Name="r2" ItemsSource="{Binding Path=.}"> </DataGrid> </StackPanel> </Window> Codebehind: using System.Data; using System.Windows; namespace Fucking_Data_Grids { public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); DataTable dt1, dt2; dt1 = new DataTable(); dt2 = new DataTable(); dt1.Columns.Add("a-name", typeof(string)); dt1.Columns.Add("b-name", typeof(string)); dt1.Rows.Add(new object[] { 1, "Hi" }); dt1.Rows.Add(new object[] { 2, "Hi" }); dt1.Rows.Add(new object[] { 3, "Hi" }); dt1.Rows.Add(new object[] { 4, "Hi" }); dt1.Rows.Add(new object[] { 5, "Hi" }); dt1.Rows.Add(new object[] { 6, "Hi" }); dt1.Rows.Add(new object[] { 7, "Hi" }); dt2.Columns.Add("a.name", typeof(string)); dt2.Columns.Add("b.name", typeof(string)); dt2.Rows.Add(new object[] { 1, "Hi" }); dt2.Rows.Add(new object[] { 2, "Hi" }); dt2.Rows.Add(new object[] { 3, "Hi" }); dt2.Rows.Add(new object[] { 4, "Hi" }); dt2.Rows.Add(new object[] { 5, "Hi" }); dt2.Rows.Add(new object[] { 6, "Hi" }); dt2.Rows.Add(new object[] { 7, "Hi" }); r1.DataContext = dt1; r2.DataContext = dt2; } } } I'll tell you what happens. The top datagrid is populated with column headers and data. The bottom datagrid has column headers but all the rows are blank.

    Read the article

  • Why does calling the YUI Datatable showCellEditor not display the editor?

    - by t-boy
    Clicking on the second cell (any row) in the datatable causes the cell editor to display. But, I am trying to display the cell editor from code. The code looks like the following: var firstEl = oDataTable.getFirstTdEl(rowIndex); var secondCell = oDataTable.getNextTdEl(firstEl); oDataTable.showCellEditor(secondCell); When I debug into the datatable.js code (either with a click or from the code above) it follows the same path through the showCellEditor function but the above code will not display the editor. I am using YUI version 2.8.0r4.

    Read the article

  • select always returns -1 while trying to read from socket and stdin

    - by Aleyna
    Hello I have the following code implemented on C++(Linux) to check on my listening socket and stdin using select. select however keeps returning -1 no matter what I try to do! What's wrong with that code :s I will appreciate any help. Thanks highsock = m_sock; //listening socket memset((char *) &connectlist, 0, sizeof(connectlist)); memset((char *) &socks, 0, sizeof(socks)); int readsocks; struct timeval timeout; timeout.tv_sec = 60; timeout.tv_usec = 0; while (1) { updateSelectList(); //cout << "highest sock: " << highsock << endl; tempreadset = readset; readsocks = select(highsock+1, &tempreadset, NULL, NULL, &timeout); //cout << "# ready: " << readsocks << endl; if (readsocks < 0) { if (errno == EINTR) continue; cout << "select error" << endl; } if (readsocks > 0) { readFromSocks(); } } void readFromSocks() { if (FD_ISSET(STDIN, &readset)) { ... } else if (FD_ISSET(m_sock, &readset)) { ... } } void updateSelectList() { FD_ZERO(&readset); FD_SET(STDIN, &readset); FD_SET(m_sock, &readset); for (int i=0; i<MAXCONNECTIONS; i++) { if (connectlist[i] != 0) { FD_SET(connectlist[i], &readset); if (connectlist[i] > highsock) highsock = connectlist[i]; } } highsock = max(max(m_sock, STDIN), highsock); }

    Read the article

  • C socket programming: client send() but server select() doesn't see it

    - by Fantastic Fourier
    Hey all, I have a server and a client running on two different machines where the client send()s but the server doesn't seem to receive the message. The server employs select() to monitor sockets for any incoming connections/messages. I can see that when the server accepts a new connection, it updates the fd_set array but always returns 0 despite the client send() messages. The connection is TCP and the machines are separated by like one router so dropping packets are highly unlikely. I have a feeling that it's not select() but perhaps send()/sendto() from client that may be the problem but I'm not sure how to go about localizing the problem area. while(1) { readset = info->read_set; ready = select(info->max_fd+1, &readset, NULL, NULL, &timeout); } above is the server side code where the server has a thread that runs select() indefinitely. rv = connect(sockfd, (struct sockaddr *) &server_address, sizeof(server_address)); printf("rv = %i\n", rv); if (rv < 0) { printf("MAIN: ERROR connect() %i: %s\n", errno, strerror(errno)); exit(1); } else printf("connected\n"); sleep(3); char * somemsg = "is this working yet?\0"; rv = send(sockfd, somemsg, sizeof(somemsg), NULL); if (rv < 0) printf("MAIN: ERROR send() %i: %s\n", errno, strerror(errno)); printf("MAIN: rv is %i\n", rv); rv = sendto(sockfd, somemsg, sizeof(somemsg), NULL, &server_address, sizeof(server_address)); if (rv < 0) printf("MAIN: ERROR sendto() %i: %s\n", errno, strerror(errno)); printf("MAIN: rv is %i\n", rv); and this is the client side where it connects and sends messages and returns connected MAIN: rv is 4 MAIN: rv is 4 any comments or insightful insights are appreciated.

    Read the article

  • Socket select() Handling Abrupt Disconnections

    - by Genesis
    I am currently trying to fix a bug in a proxy server I have written relating to the socket select() call. I am using the Poco C++ libraries (using SocketReactor) and the issue is actually in the Poco code which may be a bug but I have yet to receive any confirmation of this from them. What is happening is whenever a connection abruptly terminates the socket select() call is returning immediately which is what I believe it is meant to do? Anyway, it returns all of the disconnected sockets within the readable set of file descriptors but the problem is that an exception "Socket is not connected" is thrown when Poco tries to fire the onReadable event handler which is where I would be putting the code to deal with this. Given that the exception is silently caught and the onReadable event is never fired, the select() call keeps returning immediately resulting in an infinite loop in the SocketReactor. I was considering modifying the Poco code so that rather than catching the exception silently it fires a new event called onDisconnected or something like that so that a cleanup can be performed. My question is, are there any elegant ways of determining whether a socket has closed abnormally using select() calls? I was thinking of using the exception message to determine when this has occured but this seems dirty to me.

    Read the article

  • What data structure would be the least painful DataTable replacement?

    - by MatthewMartin
    I'm storing a lot of sorted ~10 row 2 column/key value pairs in ASP.NET cache-- they're the data for dropdownlists. Right now they are all DataTables, which isn't very space efficient (the rule of thumb is 10x increase in size when data is strored in a dataset). Old Code DataTable table = dataAccess.GetDataTable(); dropDownList.DataSource = table; Hoped for new Code Unknown data = dataAccess.GetSomethingMoreSpaceEfficient(); dropDownList.DataSource = data; What pre-existing datastructures are similar enough to DataTable that would minimize code breakage and reduce the serialized size when stored in ASP.NET cache?

    Read the article

  • Some way of getting just the data part from a web service returning a DataTable?

    - by simendsjo
    I'm using an external web service that returns a DataTable. There's a couple of problems with this. The first is that there are over 20,000 columns, and .Net crashes when trying to convert the xml to a DataTable. I have to use Mono to make this work. The other problem is that it takes a lot of time to fetch all the column information. The columns "never" changes (and when they do, I know about it in advance). I would like to just fetch the data part, and load the schema from a local file. I very much doubt this is possible, but I thought I could ask here just in case.

    Read the article

  • c unix- Select() send and receive with same socket descriptor

    - by RileyVanZeeland
    I am wanting to use select to receive and send on a client/server on the same socket descriptor (serverside). timestruct* myTime; sockfd = accept(listeningFd, 0, 0); while(1) FD_ZERO(&my_fd_set) maxFd = sockfd FD_ZERO(&my_fd_set); FD_SET(sockfd, &my_fd_set); select(maxFd+1, &my_fd_set, &my_fd_set, NULL, myTime); for (j=0; j<=maxFd; j++) if(FD_ISSET(j, &temp_fd_set)) if(j==sockfd) send() if(j==sockfd) recv() This is essentially what I want to do. Obviously this won't work because sockfd is going to be the same value for sending and receiving. Is there a way I can do this without using fork()?? Currently I have a blocking recv and send but the server could be required to recv multiple commands while another command is being processed to send back to the client. I am very knew to c and also 'select()'. Because select has the three fd_set options (read, write, execute) I thought maybe I could do this. Thank you.

    Read the article

  • C socket programming: select() is returning 0 despite messages sent from server

    - by Fantastic Fourier
    Hey all, I'm using select() to recv() messages from server, using TCP/IP. When I send() messages from the server, it returns a reasonable number of bytes, saying it's sent successful. And it does get to the client successfully when I use while loop to just recv(). Everything is fine and dandy. while(1) recv() // obviously pseudocode However, when I try to use select(), select() returns 0 from timeout (which is set to 1 second) and for the life of me I cannot figure out why it doesn't see the messages sent from the server. I should also mention that when the server disconnects, select() doesn't see that either, where as if I were to use recv(), it would return 0 to indicate that the connection using the socket has been closed. Any inputs or thoughts are deeply appreciated. #include <arpa/inet.h> #include <errno.h> #include <fcntl.h> #include <netdb.h> #include <netinet/in.h> #include <pthread.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <strings.h> #include <sys/select.h> #include <sys/socket.h> #include <sys/time.h> #include <sys/types.h> #include <time.h> #include <unistd.h> #define SERVER_PORT 10000 #define MAX_CONNECTION 20 #define MAX_MSG 50 struct client { char c_name[MAX_MSG]; char g_name[MAX_MSG]; int csock; int host; // 0 = not host of a multicast group struct sockaddr_in client_address; struct client * next_host; struct client * next_client; }; struct fd_info { char c_name[MAX_MSG]; int socks_inuse[MAX_CONNECTION]; int sock_fd, max_fd; int exit; struct client * c_sys; struct sockaddr_in c_address[MAX_CONNECTION]; struct sockaddr_in server_address; struct sockaddr_in client_address; fd_set read_set; }; struct message { char c_name[MAX_MSG]; char g_name[MAX_MSG]; char _command[3][MAX_MSG]; char _payload[MAX_MSG]; struct sockaddr_in client_address; struct client peer; }; int main(int argc, char * argv[]) { char * host; char * temp; int i, sockfd; int msg_len, rv, ready; int connection, management, socketread; int sockfds[MAX_CONNECTION]; // for three threads that handle new connections, user inputs and select() for sockets pthread_t connection_handler, manager, socket_reader; struct sockaddr_in server_address, client_address; struct hostent * hserver, cserver; struct timeval timeout; struct message msg; struct fd_info info; info.exit = 0; // exit information: if exit = 1, threads quit info.c_sys = NULL; // looking up from the host database if (argc == 3) { host = argv[1]; // server address strncpy(info.c_name, argv[2], strlen(argv[2])); // client name } else { printf("plz read the manual, kthxbai\n"); exit(1); } printf("host is %s and hp is %p\n", host, hserver); hserver = gethostbyname(host); if (hserver) { printf("host found: %s\n", hserver->h_name ); } else { printf("host not found\n"); exit(1); } // setting up address and port structure information on serverside bzero((char * ) &server_address, sizeof(server_address)); // copy zeroes into string server_address.sin_family = AF_INET; memcpy(&server_address.sin_addr, hserver->h_addr, hserver->h_length); server_address.sin_port = htons(SERVER_PORT); bzero((char * ) &client_address, sizeof(client_address)); // copy zeroes into string client_address.sin_family = AF_INET; client_address.sin_addr.s_addr = htonl(INADDR_ANY); client_address.sin_port = htons(SERVER_PORT); // opening up socket sockfd = socket(AF_INET, SOCK_STREAM, 0); if (sockfd < 0) exit(1); else { printf("socket is opened: %i \n", sockfd); info.sock_fd = sockfd; } // sets up time out option for the bound socket timeout.tv_sec = 1; // seconds timeout.tv_usec = 0; // micro seconds ( 0.5 seconds) setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(struct timeval)); // binding socket to a port rv = bind(sockfd, (struct sockaddr *) &client_address, sizeof(client_address)); if (rv < 0) { printf("MAIN: ERROR bind() %i: %s\n", errno, strerror(errno)); exit(1); } else printf("socket is bound\n"); printf("MAIN: %li \n", client_address.sin_addr.s_addr); // connecting rv = connect(sockfd, (struct sockaddr *) &server_address, sizeof(server_address)); info.server_address = server_address; info.client_address = client_address; info.sock_fd = sockfd; info.max_fd = sockfd; printf("rv = %i\n", rv); if (rv < 0) { printf("MAIN: ERROR connect() %i: %s\n", errno, strerror(errno)); exit(1); } else printf("connected\n"); fd_set readset; FD_ZERO(&readset); FD_ZERO(&info.read_set); FD_SET(info.sock_fd, &info.read_set); while(1) { readset = info.read_set; printf("MAIN: %i \n", readset); ready = select((info.max_fd)+1, &readset, NULL, NULL, &timeout); if(ready == -1) { sleep(2); printf("TEST: MAIN: ready = -1. %s \n", strerror(errno)); } else if (ready == 0) { sleep(2); printf("TEST: MAIN: ready = 0. %s \n", strerror(errno)); } else if (ready > 0) { printf("TEST: MAIN: ready = %i. %s at socket %i \n", ready, strerror(errno), i); for(i = 0; i < ((info.max_fd)+1); i++) { if(FD_ISSET(i, &readset)) { rv = recv(sockfd, &msg, 500, 0); if(rv < 0) continue; else if(rv > 0) printf("MAIN: TEST: %s %s \n", msg._command[0], msg._payload); else if (rv == 0) { sleep(3); printf("MAIN: TEST: SOCKET CLOSEDDDDDD \n"); } FD_CLR(i, &readset); } } } info.read_set = readset; } // close connection close(sockfd); printf("socket closed. BYE! \n"); return(0); }

    Read the article

  • HTML - Put SELECT tag content into INPUT type = "text"

    - by mouthpiec
    Hi, I have a form in a webpage where I would like to put the selected item in a drop down list into a testbox. The code I have till now is the following: <form action = ""> <select name = "Cities"> <option value="----">--Select--</option> <option value="roma">Roma</option> <option value="torino">Torino</option> <option value="milan">Milan</option> </select> <br/> <br/> <input type="button" value="Test"> <input type="text" name="SelectedCity" value="" /> </form> I think I need to use javascript .... but any help? :-) thanks

    Read the article

< Previous Page | 7 8 9 10 11 12 13 14 15 16 17 18  | Next Page >