JavaScript - Document.getelementsbyname() For Php Array.
I am trying to pass two inputs one hidden one text to php using document.getelementsbyname().
The hidden input is in a php array, the text input is a user typed input. When ever I pass it to php it always pulls the first item in the array. So even if I click "View" on the 3rd item in my array it will still show the two inputs from my first item in the array. Here are my html input fields followed by java function followed by submit. How do i get it to send the proper information and not the first item in the array. Code: <input name="imageNumber" type="hidden" value="<? echo $imageNumber; ?>.png"> <input type="text" name="imprint" value="" size="40"> <script> function passImprint() { imageNumber = (document.getElementsByName("imageNumber")[0].value); imprint = (document.getElementsByName("imprint")[0].value); urlString = "imprint.php?imprint=" +imprint + "&imageNumber=" +imageNumber; window.open(urlString,"width=640,height=295"); } </script> <input type="button" value="View Imprint" onClick="passImprint();"> Similar TutorialsI am trying to add a green tick or red cross to my form so that the user will know if they have filled out the form correctly before submitting it and getting told that they need to fill out this or correct that. I have added NAME to each form field and have been using this to read the content but for some reason I am unable to read what is in the field I get the error, 'undefined'. this is what code I have started on... Code: function checkValidFormInput(id, noCheck) { if (noCheck == '') { var idValue = document.getElementsByName(id); if (id == 'customerName') { alert(id); alert(idValue.value); if (idValue != '') { document.getElementsByName(id + 'Img').innerHTML = '<img alt=/"/" src=/"/">'; } } if (id == 'customerEmail') { if (idValue != '') { document.getElementsByName(id + 'Img').innerHTML = '<img alt=/"/" src=/"/">'; } } } } my code is still in the early stages and is missing the other parts to place a red cross, as the moment i am working on placing the green tick. Can anyone spot what I have wrong in my code that is causing it not to read the form field. my form field is coded as so.. Code: <li class="value"> <input type="text" autocomplete="off" name="customerName" value="<?=$fullname;?>" style="width: 200px;" onChange="checkValidFormInput(this.name, '');"> <div style="float: left;" id="customerNameImg"></div><br style="clear:both"> </li> I have to update the rowid(assigned to checkbox) whenever the textbox value is updated and this needs updating value of document.getElementsByName('rf_select[]') when checkbox value matches the textbox id. There can be mutliple number of rows each with a uniqueID (checkbox value) that matches with the textboxID onload. Code :- <td align="center"><input type='checkbox' name='rf_select[]' id='rf_select' value="rowId" CHECKED border="none"/> <td align="left"><input type='text' name='policy_no' id="rowId" size='25' value="test" onBlur=handleRowId('policy_no'); /></td> <script language="javascript"> function handleRowId(){ var arr = new Array(); var rowarr = new Array(); arr = document.getElementsByName('policy_no'); rowarr = document.getElementsByName('rf_select[]'); for(var i = 0; i < arr.length; i++) { var obj = arr.item(i); //alert(obj.id + " = " + obj.value); for(var j=0; j< rowarr.length; j++){ if(rowarr[j].value == obj.id){ document.getElementsByName('rf_select')[j].value = rowarr[j].value+"#@#"+obj.value; } } } } </script> I am having problem assigning values here - document.getElementsByName('rf_select')[j].value = rowarr[j].value+"#@#"+obj.value; Any help is appreciated. Hi, I'm trying to use the getElementsByName method in a div tag and it's retrning an error. Can anyone suggest how to access it from a javascript function After some severe experimentation I got to googling for an answer and stumbled upon these forums. So my big question is, is it possible to use getElementsByName() with a variable as the parameter? And if not what is another way I can get at each element based on a variable list of names. Code: var curObjSet = document.getElementsByName(String(idStack[y])).item(0) I'm trying desperately to make my code organic and not to have to hard code field names but without this working its leaving me with out options. Thank you for any time and help provided. - Eric In my program there is table which is retrieved and then there radio buttons, after selecting any radio button other columns get exapanded into textboxes to edit info. Now for expansion I have used div<id = > tag for each textbox and In javascript I have a function for showing textbox after clicking a radio button.In that I have used , arr.length=Length of the rows in table function edit1(el) { for(var i=0;i<arr.length;i++) { if(el.value==arr[i].value) { //document.getElementById("test[" + i + "]").value Not workking //document.getElementById('dname['+ i + ']').style.display = block"; Not working document.getElementById('dname').style.display = "block"; document.getElementById('dmarks').style.display = "block"; break; } else { document.getElementById('dname').style.display = "none"; document.getElementById('dmarks').style.display = "none"; } }//end for }//end if } In HTML, while($row1=mysql_fetch_array($rs1)) { echo "<tr>"; /*<td>44:<div id=d4 style="display:none;"><input type=text name=t4 id=idtext></div></td></tr><br>*/ ?> <td><input type="radio" name="select" value="<?php echo $row1['rollNo'];?>" onClick='updateRec(this);'><?php echo $row1['rollNo']; ?> <input type="radio" name="select" value="<?php echo $row1['rollNo'];?>" onClick='hiding(this);'>hide</td> <td><?php echo $row1['name']; ?><div id="dname[]" style="display:none;"><input type=text name="tname[]"></div></td> <td><?php echo $row1['marks']; ?><div id="dmarks[]" style="display:none;"><input type=text name="tmarks[]"></div></td> </tr><br> <?php } // end while ?> </table><br><br> Here I have to take array of div id's = "dname[]" but don't know the syntax for document.getElementById('dname').style.display = "block"; in which dname is array Plz help. Hi.. I have problem on how can I automatically display the output from the computation (Demanded Qty * Quantity), after or while I input Demanded Qty. I mean I input Demanded Qty, on below it will display the output also beside the SubItems. Sorry, if i post again my problem, because I have no idea on how can I solve this problem. here is my code: PHP Code: <?php error_reporting(0); date_default_timezone_set("Asia/Singapore"); //set the time zone $con = mysql_connect('localhost', 'root',''); if (!$con) { echo 'failed'; die(); } mysql_select_db("mes", $con); ?> <html> <title>Stock Requisition</title> <head> <link rel="stylesheet" type="text/css" href="kanban.css"> <script type="text/javascript"> function compute_quantity(){ var DemandedQty = document.getElementById('DemandedQty').value; var SubQty = document.getElementById('SubQty').value; var Quantity = document.getElementById('Quantity').value; SubQty = (DemandedQty * Quantity); } </script> </head> <body> <form name="stock_requisition" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <div> <table> <thead> <th>Items</th> <th>Sub Items</th> <th>Item Code</th> <th>Demanded Qty</th> <th>UoM</th> <th>Class</th> <th>Description</th> <th>BIN Location</th> </thead> <?php $DemandedQty = $_POST['DemandedQty']; $sql = "SELECT DISTINCT Items FROM bom_subitems ORDER BY Items"; $res_bom = mysql_query($sql, $con); while($row = mysql_fetch_assoc($res_bom)){ $Items = $row['Items']; $Items_ = substr($Items, 12, 3); echo "<tr> <td style='border: none;font-weight: bold;'> <input type='name' value='$Items_' name='Items_[]' id='Items' readonly = 'readonly' style = 'border:none;width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;'></td> <td style='border:none;'> </td> <td style='border:none;'> </td> <td style='border: none;'><center><input type='text' name='DemandedQty[]' id='DemandedQty' value='' size='12' onkeyup = compute_quantity()></center></td> </tr>"; $sql = "SELECT Items, SubItems, ItemCode, UoM, Class, Description, BINLocation, Quantity FROM bom_subitems WHERE Items = '$Items' ORDER BY Items"or die(mysql_error()); $res_sub = mysql_query($sql, $con); while($row_sub = mysql_fetch_assoc($res_sub)){ $Items1 = $row_sub['Items']; $SubItems = $row_sub['SubItems']; $ItemCode = $row_sub['ItemCode']; $UoM = $row_sub['UoM']; $Class = $row_sub['Class']; $Description = $row_sub['Description']; $BINLocation = $row_sub['BINLocation']; $Quantity = $row_sub['Quantity']; echo "<input type='hidden' name='Quantity' id='Quantity' value='$Quantity'>"; echo "<tr> <td style='border: none;'> <input type='hidden' value='$Items1' id='Items1' name='Items1[]'></td> <td style='border: none;'> <input type='text' name='SubItems[]' value='$SubItems' id='SubItems' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;'></td> <td style='border: none;'> <input type='text' name='ItemCode[]' value='$ItemCode' id='ItemCode' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;'></td> <td style='border: none;'><center><input type='text' name='SubQty[]' id='SubQty' value='' size='12' style></center></td> <td style='border: none;' size='3'> <input type='text' name='UoM[]' value='$UoM' id='UoM' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='3'></td> <td style='border: none;'> <input type='text' name='Class[]' value='$Class' id='Class' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;'></td> <td style='border: none;'> <input type='text' name='Description[]' value='$Description' id='Description' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size= '30'></td> <td style='border: none;'> <input type='text' name='BINLocation[]' value='$BINLocation' id='BINLocation' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;'></td> </tr>"; } } ?> </table> </div> </form> </body> </html> If you don't understand my issue feel free to ask me for further understanding. I'm sorry again I really need to solve this and i tried to google but I can't find the solution. Thank you so much I have one question about <style> elements, are they counted in document.styleSheets array? and can I add rules to them by using insertRule() and deleteRule() methods?
My code is here and it works ... However, I would like my dynamic table to show on the same page as my body and not on a new blank page. I have created a DIV and try playing around with the document.getElementById('monTab').innerHTML but it's not working out for me ... What am i missing ? Regards, Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD><TITLE>new Script - Javascript Cours 11</TITLE> <META content="text/html"; charset="UTF-8" http-equiv="content-type"> <SCRIPT type="text/javascript"> function createTable(){ var Etudiant = new Array(Number(prompt("How many Students will you put in ?",""))); document.write("<table border=\"1\">"); for (var i=0; i<Etudiant.length; i++) { Etudiant[i] = window.prompt("S'il vous plait entrez le nom d'un etudiant " + (i+1) + ".","") alert("Nice to see you "+Etudiant[i]); document.write("<td>"+Etudiant[i]+"</td>"); j = parseInt(prompt("Combien de notes voulez vous calculez ?")); for (h=0;h<j;h++){ notes[h] = parseInt(prompt("S'il vous plait entrez la "+(h+1)+" note de "+Etudiant[i])); document.write("<td>"+notes[h]+"</td>"); } document.write("<tr>"); } document.write("</tr>"); document.write("</table>"); document.getElementById('monTab').innerHTML=Etudiant; } </script> <BODY> <H1>Combien de note voulez vous cumulez ?</H1> <br> <br> <input type="button" name="btnSubmit" value="TRY IT" onclick="createTable()"> <div id="monTab" size="10"> Content should come here ...Content should come here ...Content should come here ...Content should come here ...Content should come here ...Content should come here ...Content should come here ... </div> </BODY> </HTML> I found this line in one of the scripts on javascript.kit <code> if(document.layers|| document.getElementById|| document.all) </code> Could someone give me an idea on why this line would be used in a code? Thank you very much I'm working on a website that will basically embed a widget/frame sent by a handler into a user's current page. The user basically adds a script tag to where they would like the HTML to be. The script tag has their settings and is basically a document.write that calls all the code that we want displayed. So here's my problem. We have a map that we need to add in a specific section, and to get the map we have to call another script tag. So we end up having a script tag (map) embedded in another script tag (the code for the widget/frame) or we end up having to document.write inside a document.write. Now this works just fine and as expected in Firefox, Safari, and Chrome. However, Internet Explorer and Opera wait until the first document.write is completely finished before calling the embedded one. Of course the problem with this, is that it takes the map out of the document's flow and just appends it to the bottom left of the page. Since the rest of the page has already been called, there's no way to move the interior "map" script. Any ideas? Basically just trying to figure out how (if even possible) to render an embedded script tag in Internet Explorer and be able to place it properly. I've tried everything that I can think of, including AJAX and Google's unescape script. Any suggestions, I'd greatly appreciate it. Or even if you've encountered a similar problem, and know that it just isn't possible in IE or Opera, that would be fine too. Thanks in advance! What is an alternative to document.write? I know I could use <p> in html </p> I would like to use JS though. I hope you can understand my question. I am 14yo and this is not for homework. I just wanna try and learn JS. I read document.write can cause me problems. But all I ever see is: <script type="text/javascript"> document.write("any words"); </script> what alternate could I use? Hello everyone. I'm having a little problem with creating a element in internet explorer. The element that I'm creating is a div with a few style attributes to to it. The div is suppose to cover the whole page almost like a black transparent window on the page. However it is not. The messed up part about this is that it works fine in Firefox, google chrome and I'm sure other browsers (though haven't tested) and when I go to apply the div in my actual code as javascript is suppose to when you tell it create it, it works fine. No problems whatsoever... I'm not to sure what I'm doing wrong here and it would be great if I could get some help with this. Thanks Code: function showPhotoUpload() { var overlay = document.createElement("div"); overlay.setAttribute("style","z-index:3; background:#111111; width:100%; height:100%; position:absolute; top:0; opacity:0.5; filter:alpha(opacity:50);"); document.body.appendChild(overlay).lastChild; } Hi, I need to open a PDF file via a web page. Basically, I want to have a textbox where I type in a filename and then click submit and it will open that document. For example, I need to open a PDF document... I need to have a text box where I can input "test1" for example, click "GO" and it will add the "C:/test/" + textbox value + ".pdf" and open it in the browser. I could do it in PHP but this is going to run on a local machine with no serverside so I assume JS will be the way forward. Any ideas? Many Thanks MJFCAD I have a html file and a separate javascript file. The html file contains: <input type="reset" id = "resetButton" /> I want a message to pop up if the reset button is pressed. So in the js file I have: document.getElementById("resetButton").onclick = doAlert; doAlert is a function that simply does: alert("Do you want to reset?"); I know my separate js file is linked correctly because if I just put in alert("hello"); in the js file then it works. But if I use the document.getElementById thing in the js file, then there is an error. The error, according to the error console, says that "resetButton" is null. Can someone help me? thanks! btw, I'm totally new to programming...and I need to do this for my homework assignment I'm sorry if this question seem very basic but I just start learning javascript. I would like to display an image but not sure why it is not working. In a nutshell, here's my code Code: <html> <head></head> <body> <script type="text/javascript"> document.writeln("<img src=/"xMark.jpg /" width=25 height=25 >");</script> </body> </html> Hi, I am trying to create a xml document and load it into a 3rd party function as follows: Quote: var doc = new ActiveXObject('Microsoft.XMLDOM'); // OR var doc = document.implementation.createDocument('', 'xml', null); o.overlayKML('somefile.xml'); // Works perfectly o.overlayKML(doc); // Doesn't work at all, return unsupport error I get to know that the overlayKML (3rd party function) needs to read a physical file with a path and sadly it doesn't support DOM. How can I create a javascript document that mimic a physical file and introduce it into the function? Thanks! Dear Great Coders, I am having some trouble to get the id of the parent of a document which is iframe1 here. As you can see it the <javascript> is residing in the javascript section. Do mind giving me some ideas? Yes, I know. I can insert the javascript on the top, but believe me i cant for some purpose because I am intergrating many other codes into it. <html> <iframe id="iframe1"> <html> <head> <javascript> </head> <body> </body> </html> </iframe> </html> Code: document.getElemetById... is that it, or could be somehow done: Code: anyElement.getElemetById... ? Tryed and it did not work. i want to search the index.xml file throu diff input like combo box and input text shown in the search.html file and output the result in a tale. search.html Code: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html><head><meta content="text/html; charset=ISO-8859-1" http-equiv="content-type"> <title>Search</title> <script type="text/javascript" src="search%20xml/search%20xml%20with%20mouseover%20table/searchindex.js"></script> </head><body> <form name="frmMain" id="frmMain" action=""> <b>Search Document: <br> <br> <br> Choose Book <select name="Select1"> <option selected="">--All--</option> <option>b1</option> <option>b2</option> </select><br> <br> Choose year <select name="Select2"> <option selected="">--All--</option> <option>1979</option> <option>1980</option> </select><br> </b><br> <strong>Doc_No</strong> <input name="Text1" type="text"><br> <br> <strong>Subject</strong> <input name="Text2" type="text" style="width: 356px"><br> <br> <input value="Submit" onclick="searchIndex(); return false;" type="submit"> </form> </body> </html> index.xml Code: <?xml version="1.0" ?> <books> <book name="b1"> <year date="1979"> <Document Doc_No="17" Subject="s1" path="ta3amime\1979\17_1979.tif">17_1979_s1.tif</Document> <Document Doc_No="18" Subject="s2" path="ta3amime\1979\18_1979.tif">18_1979_s2.tif</Document> </year> <year date="1980"> <Document Doc_No="19" Subject="s3" path="ta3amime\1980\19_1980.tif">19_1980_s3.tif</Document> <Document Doc_No="6" Subject="s4" path="ta3amime\1980\6_1980.tif">6_1980_s4.tif</Document> <Document Doc_No="1" Subject="s5" path="ta3amime\1980\1_1980.tif">1_1980_s5.tif</Document> <Document Doc_No="7" Subject="s6" path="ta3amime\1980\7_1980.tif">7_1980_s6.tif</Document> <Document Doc_No="4" Subject="s7" path="ta3amime\1980\4_1980.tif">4_1980_s7.tif</Document> </year> </book> <book name="b2"> <year date="1979"> <Document Doc_No="8" Subject="s8" path="ta3amime\1979\8_1979.tif">8_1979_s8.tif</Document> <Document Doc_No="7" Subject="s9" path="ta3amime\1979\7_1979.tif">7_1979_s9.tif</Document> </year> <year date="1980"> <Document Doc_No="9" Subject="s10" path="ta3amime\1980\9_1980.tif">9_1980_s10.tif</Document> <Document Doc_No="1" Subject="s11" path="ta3amime\1980\1_1980.tif">1_1980_s11.tif</Document> <Document Doc_No="8" Subject="s12" path="ta3amime\1980\8_1980.tif">8_1980_s12.tif</Document> <Document Doc_No="14" Subject="s13" path="ta3amime\1980\14_1980.tif">14_1980_s13.tif</Document> <Document Doc_No="16" Subject="s14" path="ta3amime\1980\16_1980.tif">16_1980_s14.tif</Document> </year> </books> searchindex.js Code: window.onload = loadIndex; function loadIndex() { // load indexfile // most current browsers support document.implementation if (document.implementation && document.implementation.createDocument) { xmlDoc = document.implementation.createDocument("", "", null); xmlDoc.load("index.xml"); } // MSIE uses ActiveX else if (window.ActiveXObject) { xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async = "false"; xmlDoc.load("index.xml"); } } // What would be the searchIndex() function ????? // Result in a table What I'm trying to get are the tag ids separately after I call the callback function. I've been racking my brain for far too long on this one. Here is a shorter version of what I have. I'm using the array's length to count and break into their own lines. How do i get all 9 id="hover_[index]" separately using my array length? PHP Code: var info = Array("bla_1", "bla_2", "bla_3", "bla_4", "bla_5", "bla_6", "bla_7", "bla_8", "bla_9"); function callback(results, status) { if (status == myStatus) { for (var i = 0; i < results.length; i++) { send(results[i]); } } } function send(info) { document.getElementById('results').innerHTML += "<div id='hover_"+info.length+"'>Something</div>"; hover_target = document.getElementById('hover_'+info.length);// how do i get all 9 hover_[index] separately? someEvent.addDomListener(hover_target, 'mouseover', function() { // do something }); } Thank you so much in advance, Frank |