JavaScript - How To Fetch Value From Multiselect Box
Hi All,
Can any one help me in fetching the value from multiselect box. I am writing syntax like this : <select id="status" name="status" multiple="multiple" size='2'> <?php for($i=0; $i<count($status); $i++) { echo "<option value='".$status[$i]['osp_details_id']."'>". $status[$i] ['description']."</option>"; } ?> Now in javascript how can I fetch the values selected by the user. Similar TutorialsHi all! I'm using a multiselect box on my website, similar to this one: <Select Name="multiselect[]" multiple="multiple"> <option>This is option 1</option> <option>This is option 2</option> <option>This is option 3</option> <option>This is option 4</option> </select> Now I want to set option 1, option 2 and option 3 as selected (highlighted) in javascript. How would I go about doing this? I tried something like this: document.taakform.elements['multiselect[]'].selectedIndex = "1" document.taakform.elements['multiselect[]'].selectedIndex = "2" document.taakform.elements['multiselect[]'].selectedIndex = "3" Of course this doesn't work (else I wouldn't be posting here ), but I hope you catch my drift. Thanks in advance guys (and gals)! I run VLD personals script and would like to show a birthday cake when the time is right for a person. The VLD script outputs the birthday as following: 05 December, 1974 I almost found a sollution by the code below until I realised the years don't match. How can this be resolved? The following code produces: 24 June, 2010 Quote: <script type="text/javascript"><!-- function makeArray() { for (i = 0; i<makeArray.arguments.length; i++) this[i + 1] = makeArray.arguments[i]; } var months = new makeArray('January','February','March','April','May', 'June','July','August','September','October','November','December'); var date = new Date(); var day = date.getDate(); var month = date.getMonth() + 1; var yy = date.getYear(); var year = (yy < 1000) ? yy + 1900 : yy; document.write(day + " " + months[month] + ", " + year); //--></script> So if I could find a way to match the day and month with todays, it might be great to have a birthdaycake on a members profile, isn't it? I have this variable from the VLD script and can do as following I guess: Quote: <!-- IF {profile_field_age_value} == "todaysdate" --> show IMG Could anybody help me a bit further? Thx ! :-) I am trying to get a form value on an action page using JavaScript to alert the value. The below doesnt alert anything after I hit the submit button in the one.html page: one.html Code: <form action="two.html" method="get" id="myform"> <input type="text" name="city"> <input type="submit"> two.html Code: <html> <head> <script> alert(document.myform.city.value); </script> </head> <body> </body> </html> Please advise. How to fetch only month from an already existing date text box... eg:05-09-2009(dd-mm-yyyy), i just want to fetch only month(09) in another text box I am trying to Iframe page of some site but I they have blocked, if I try to iframe anygiven page on that site, it would automatically take to the index page of that site. plz show me any other solution thank you Hello, I'm working on a somewhat interactive script that uses dynamic content and I'm quite new to javascript so I was wondering how I could download contents from a source such as a file that would give plain text output, display the output and then the client would wait for X seconds before refreshing the content(Discarding the old content)?
im having issue with fetching answers from database by json file it says error once i click finish button, what do you think the error could be? here is the responses.php file code: and here is the js code that pulls answers Code: $.ajax({ url :'reponses.php', type : 'POST', data : 'fetchAnswers=' + answerCode + '&id_examens=' + examensId, dataType : 'json', success : function(data){ $(lastButton).html('Finish'); answers =data;// $.parseJSON(data); $(dataDiv).data('answer', answers); callback(answers); }, error : function(resultat, statut, erreur){ $(lastButton).html('Finish'); alert('There was a problem with your network connection. Please click "Finish" again to re-try. If the problem persists, you will have to wait until network connectivity has been restored.'); }, complete : function(resultat, statut){ } }); } else { answers = $(dataDiv).data('answer'); $(lastButton).html('Finish'); callback(answers); } } } when i click the finish button it shows the alert message instead of bring answer and proceed Reply With Quote 01-17-2015, 06:18 PM #2 yamizer View Profile View Forum Posts New to the CF scene Join Date Jan 2015 Posts 2 Thanks 0 Thanked 0 Times in 0 Posts sorry i forgot to add responses.php file codee Code: <?php include("config.php"); header('Content-Type: application/json'); $answers=array(); $sql_questions = 'SELECT * FROM question '; $res_questions = mysql_query($sql_questions); while($data_questions=mysql_fetch_array($res_questions)){ $id_question=$data_questions["id"]; //$sql_answers = "SELECT * FROM reponse WHERE id_question=".$id_question." AND rep_correcte='1'"; $sql_answers = "SELECT * FROM reponse WHERE id_question=".$id_question;//." AND rep_correcte='1'"; $res_answers = mysql_query($sql_answers); $i=1; while($data_answers=mysql_fetch_array($res_answers)){ if($data_answers["rep_correcte"]==1) { $answers[]=$i;//$data_answers['id']; } //$answers[]=$data_answer["rep_correcte"]; $i++; } }//["1","6"] // $answers=array(1,6); echo json_encode($answers); /* $answers=array(1,3,2,1,1,4,1); echo json_encode($answers); */ exit(); ?> Reply With Quote 01-19-2015, 05:44 AM #3 Old Pedant View Profile View Forum Posts Supreme Master coder! Join Date Feb 2009 Posts 28,311 Thanks 82 Thanked 4,754 Times in 4,716 Posts That is TERRIBLE TERRIBLE PHP coding! (Well, actually SQL coding!) NEVER NEVER do a SELECT *inside* a PHP loop that results from a different SELECT!! But the PHP code makes no sense in any case. You are invoking that page from the JSON code with parameters: Code: 'fetchAnswers=' + answerCode + '&id_examens=' + examensId Yet NOWHERE in the PHP code are you USING those parameters! That is, you should be doing PHP Code: $answerCode = $_POST["answerCode"]; $id_examens = $_POST["id_examens"]; and then USING those values in your PHP code, probably to SELECT the correct records! I am creating a customized home page that can display regular links and login forms. I am adding Gmail login form into it. I can further customize it by putting multiple sign in buttons that can fill in username/password for different accounts before submitting. Here's the preview: http://imgur.com/s4Ert.jpg Now the problem is, in Gmail login form a hidden variable called "dsh" is filled with a value that is matched with server as well as a cookie, this value changes in some hours. So this means that I cannot create a complete offline form, but is it possible to load the login page hidden, and catch the value from it? I tried with an iframe with display:none and src="http://mail.google.com" but it opened in the top frame. Any other ideas? In short, what we need is, every time a page is opened from my computer, an online page should be open invisible from the user, and a hidden form value is to be fetched from it. Hi All. I have a dropdown list on a web form containing dates. My Question: How can I call data for that selected item(date) from a MySQL database and display it to the user? And more specifically, if that selected date has no data in the data base, I want to be able to display that as well. I'm looking for a Javascript solution, and if possible a php solution. Thank You! Hi, I am new to javascript, Please help me with the issue below. My javascript code below should actually fetch the data from html table on button click. function displaymessage() { alert ("button pressed"); var table_cells = new Array(); var table7 = document.getElementById('Auth'); for (i=0,n=table7.rows.length; i < n ; i++) { var Rowdata = table7.rows[i]; table_cells[i] = new Array(); for(j=0,cols = Rowdata.cells.length; j < cols; j++) { table_cells[i,j] = Rowdata.cells[j].innerHTML; alert (table_cells[i,j]); } } alert (table_cells[1,1]); alert (table_cells[2,1]); alert (table_cells[3,1]); alert (table_cells[4,1]); alert (table_cells[5,1]); alert (table_cells[6,1]); alert (table_cells[7,1]); alert (table_cells[8,1]); } The problem with my code above is that the statement "alert (table_cells[i,j]);" executes properly and shows the correct value. But the other alert statements shows only the value of the last row of the table. i.e., my table has 9 rows. and all the alert statements shows 9th row's 2nd column's value outside the for loop. But inside the for loop it executes fine. I tried it in IE7. I seem to miss something. Could someone please help me out with this? Thanks in advance. I am trying for a javascript code that would ask for the excel file location when run, fetch data from two columns till eof in an excel file (MS Excel 2010), append it to an existing text file and upload the plain text file to an ftp location. The ftp username, password and location needs to be hard coded in the script. Is this possible? |