![]() |
| ||
| Urgent.....Dynamic Changes.... Hi, This is Nandoo,new to webDeveloper.I want to make a script which should work in the following manner. In my web page,I want to have a button(with name add).whenever i click that button it should generate a select list and also 3 text Fields. Whenever i select the list items the text fields should change accordingly. I am struggling for the past 4 days here since i m babe to WebDeveloping. plz help me.. i have created the generation of selection List and also text fields.Now i need to change the text based on the selected items. plz... I dont know how to get the selection list in another javascript function so that i could change the values of the text boxes plz i m a new guy ...reply me urgent plz <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html lang="en"> <head> <title>DOM form elements</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <script type="text/javascript"> function appendtable() { var div = document.getElementById("divide"); var ControlsDesign = document.createElement("div"); var table_cd = document.createElement("table"); var tr_cd = document.createElement("tr"); var td_cd = document.createElement("td"); var table_content = document.createElement("table"); var tr = document.createElement("tr"); var td = document.createElement("td"); var oSelect=document.createElement("select"); var oOption = document.createElement("OPTION"); var t = document.createTextNode("Ferrari"); oOption.setAttribute("value", 4); oOption.appendChild(t); oSelect.appendChild(oOption); var oOption1 = document.createElement("OPTION"); var t = document.createTextNode("Fessari"); oOption1.setAttribute("value", 4); oOption1.appendChild(t); oSelect.appendChild(oOption1); var txt1=document.createElement("input"); txt1.type="text"; txt1.value="mamu" var txt2=document.createElement("input"); txt2.type="text"; txt2.value="Machan" var txt3=document.createElement("input"); txt3.type="text"; txt3.value="maplai" td.appendChild(oSelect); oSelect.onchange="txtChange()"; td.appendChild(txt1); td.appendChild(txt2); td.appendChild(txt3); tr.appendChild(td); table_content.appendChild(tr); td_cd.appendChild(table_content); tr_cd.appendChild(td_cd); table_cd.appendChild(tr_cd); ControlsDesign.appendChild(table_cd); div.appendChild(ControlsDesign); document.getElementById("divide").innerHTML = document.getElementById("divide").innerHTML; } function txtChange() { var di = document.getElementsByTagName("select"); //when i tried to get the selected value its showing error. } </script> <style type="text/css"> <!-- /* cascading style sheet */ --> </style> </head> <body> <input type="button" onclick="appendtable()" value="Press me"> <div id="divide"></div> </body> </html> thanks in advance.... nandoo |
| ||
| Re: Urgent.....Dynamic Changes.... Hi, I don' think you have worded your question very well. And I am not sure why you want to create this content in this manner (though perhaps its just POC and you'll reveal your true ideas later?). Anyhow, I think that your problem is your understanding of the getElementByTagName function. This function returns a list of elements matching the argument name. In this case "SELECT". Even if there is only one such element, it will be returned in a list. So you'd need to retrieve it using the item method.. i.e. di.item(0). I have edited your code, so I could get a feel for what you were after and how you were doing it. I think I've created something along the lines you were after, that is also a little simpler to read and follow. It seemed sensible to me to pass the node that created the event as an argument to the function, this way you won't have to search for it when it gets there... apart from that; the only other difference is it runs in Mozilla as well... Which is a trend in almost all my code as Mozilla is much simpler to debug than IE.
enjoy. |
| ||
| Re: Urgent.....Dynamic Changes.... hi Foo, Just read the code and give me a solution.My question will be after the code... <html> <head> <title> working with jscript</title> <script> function appendtable() { var parent = document.getElementById("divide"); div = document.createElement("div"); var tbl=div.appendChild(document.createElement("table")); var tb=tbl.appendChild(document.createElement("tbody")); var tr=tb.appendChild(document.createElement("tr")); var td=tr.appendChild(document.createElement("td")); parent.appendChild(div); var oSelect=document.createElement("select"); var oOption = document.createElement("option"); var t = document.createTextNode("Ferrari"); oOption.setAttribute("value", 0); oOption.appendChild(t); oSelect.appendChild(oOption); var oOption1 = document.createElement("option"); var t = document.createTextNode("Fessari"); oOption1.setAttribute("value", 1); oOption1.appendChild(t); oSelect.appendChild(oOption1); oSelect.onchange=function() {txtChange(this,pname,price);} var pname=document.createElement("input"); pname.type="text"; pname.value="product name" var price=document.createElement("input"); price.type="text"; price.value="product price" var qty=document.createElement("input"); qty.type="text"; qty.value="product quantity" var sku=document.createElement("input"); sku.type="text"; sku.value="product SKU" var upc=document.createElement("input"); upc.type="text"; upc.value="product UPC" td.appendChild(oSelect); td.appendChild(pname); td.appendChild(price); td.appendChild(qty); td.appendChild(sku); td.appendChild(upc); } function txtChange(obj,pname,price) { alert(obj.selectedIndex+" "+obj[obj.selectedIndex].text) var elt=obj[obj.selectedIndex].text return obj; } </script> </head> <body bgcolor=white> <FORM ACTION=DList.html METHOD=POST> Purchase Order ID <input type="text" name="poId"><br> Sendor Address <input type="text" name="senderAddress"><br> Vendor Address <input type="text" name="vendorAddress"><br> poStatus <input type="text" name="poStatus"><br> poDate <input type="text" name="poDate"><br> expDate <input type="text" name="expDate"><br><br> <h4> Product Details</h4> <input type="button" onclick="appendtable()" value="Add Product"> <div id="divide"></div> <input type="hidden" name=pId value=elt> <input type="hidden" name=pName value= pname.value > <input type="hidden" name=price value=price.value> <input type="hidden" name=pQty value=qty.value> <input type="hidden" name=SKU value=sku.value> <input type="hidden" name=UPC value=upc.value> <br> <input type="submit" name="btnSubmit" value="Submit Order"> </form> </body> </html> in my <body> tag how can i get the pname value,qty value which is built by dhtml thanks in advance nandoo Plz its really Urgent i m trying hard in each and every step but still i m not able to finish bcoz of less xperience in web developing plz |
| ||
| Re: Urgent.....Dynamic Changes.... Hey, I like the use of the anonymous function pointer... does this work in Internet Explorer? You should use the code block when your posting code in a post. It makes it easier to reasd and edit.. Checking it out now. alpha_foobar |
| ||
| Re: Urgent.....Dynamic Changes.... ok, it makes a little more sense now... I'm afraid I am working on linux here and only using mozilla, so any code I post will only be checked on Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.5) Gecko/20050110 Firefox/1.0 (Debian package 1.0+dfsg.1-2) a couple pointers, if your checking for updates now: [1] You need to set the value of the hidden fields in the txtChange function, you cannot assign them inline like this, a textfield will not update itself like this. [2] I like you anonymous function, but it won't understand what the other arguments are when it gets called. It understands 'this', because it is called by a dom object that can be referred to that way.. it doesn't understand pname etc because those variables are out of scope. ... there will be more later. alpha_foobar |
| ||
| Re: Urgent.....Dynamic Changes.... whoop... here you go... the changes:
|
| ||
| Re: Urgent.....Dynamic Changes.... help me fooBar I tried your comments.But i am not getting the right solution what i need? here i enclosed the coding.i want the dom objects price,qty,oselect,name,sku and upc in the html body tag so that it can be submitted into another pages. here i want each and every element in each row to be collected and sent to the next place not the last element alone plz help me <html> |
| ||
| Re: Urgent.....Dynamic Changes.... Its not far from giving you what you want i think, you just missed that i gave pname a name attribute: pname.name = "pname"; you'll need to do this with the other text boxes you'd like to extract as well. ok, the other change is you'll need to remove all the parameters you added to the txtChange function, refer to my last posts. they are worthless (out of scope). and you need to actually get the fields you want to assign a value to... otherwise how will they get the value? you can use my elementOfName function.. just pass document and the name you want. faster would be using the elementById function.. but you'll need to give you input fields unique id's. |
| ||
| Re: Urgent.....Dynamic Changes.... Hi fooBar, Sorry to disturb u again.BUt i have no other way since i am not that much familiar with DOM& DHTML Now i have made whatever changes u told but i am not able to get the values in the hidden fields pName,price,pQty,SKU,UPC. Last 1 week i m struggling with this problem. <html> |
| ||
| Re: Urgent.....Dynamic Changes.... Well its easy now...
notice that you search the document node for the node with the name "pName", so this name needs to be unique. A better way, would be to use the getElementyId function.. but this needs a unique id. i.e. you'll need to this:
then you can do this:
|
| ||
| Re: Urgent.....Dynamic Changes.... Though I think you'd be surprised how much DOM you know now! |
| ||
| Re: Urgent.....Dynamic Changes.... hi foo, U know i m working webMethods Integration part.In that i need the jsp page to get the input of purchase order.thats the reason i m working in jsp.to get the product details i went in the way of DOM. but now i finished the part in webMethods but jsp makes me to struggle here.i did the changes what u advices but still no result. could u please look into it deeply pleas thanks a lot.. <html> |
| ||
| Re: Urgent.....Dynamic Changes.... I think the problem is my understanding of what you want to achieve. I don't see any problem with the result, from what I understand you are trying to do. Of course I can see why this would make any sense. Oh and there is no reason to include a taglib here, your not using any JSP elements that I noticed... Cheers, alpha_foobar |
| ||
| Re: Urgent.....Dynamic Changes.... foo, Once again i will xplain the scenario. i m working in business to bussiness integration tool.we just need the jsp form to get the user input and assign the retrived values into the integraion tool. for that i need a purchase order format page,which should have the purchase order header: purchase-order_id senderID receiverID postatus podate expdate purchase order detail: productID productName productPrice productQuantity productSKU productUPC the purchase order detail should be generated according to the user needs. for example if the user wants 2 product items to be purchased then the detail should generated as follows productID 1 productName product1 productPrice 89 productQuantity 9 productSKU 678 productUPC 465 productID 2 productName product2 productPrice 890 productQuantity 49 productSKU 6738 productUPC 4635 but the purchase order header should be unique for both the product purchase-order_id 123 senderID x receiverID y postatus open podate 7/08/2005 expdate 9/08/2005 i dont know the number of items the user is going to order for that reason i used DOM for dynamic field generation is there any solution for this problem please give me the solution thanks a lot foo.. |
| ||
| Re: Urgent.....Dynamic Changes.... well, if you looked at the output forwarded to you, you would see that all the dynamically created dom objects send you a value. This value is an array if more that one field with the same name exist. which is why I don't understand why you'd want to assign the value to your hidden fields... especially not in a manner where it is the last row a user selects that is associated (this seems to be of little use apart from an excellent way of showing how to traverse the DOM). Here is the name value pairs I got from playing: SKU='product SKU 3' Now do you see my point? You haven't shown me any good reason for the hidden fields (yet). |
| ||
| Re: Urgent.....Dynamic Changes.... yes foo there is no need for hidden fields i have changed a code a littile bit and its working properly now.Thank you very much for your help.here is my code sorry here is our code <html> now i am moving to next level. yes i want the selection list option values to be generated from the result set of oracle database. since the selection list was generated using dom would there be any problem.? |
| All times are GMT -4. The time now is 4:27 am. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC