JavaScript - Dynamically Adding Text Box?
Similar TutorialsHi, I am using a javascript datepicker which works fine with simple textboxes: For example: I have a textBox startDate1 in the table below: <form method="post" name="upload" action=""> <table id="tableId"> <tr> <td> <input type="text" name="startDate1" value="" readonly="true" size="10"/> <script language="JavaScript"> new tcal ({'formname': 'upload','controlname': 'startDate1'}); </script> <td> </tr> <table> </form> --Now I want to add rows dynamically to this table for which I have <a href="javascript:addRowToTable();" >Add Row</a> and the corresponding javascript function: <script type = "text/javascript"> function addRowToTable() { var tbl = document.getElementById('tableId'); var lastRow = tbl.rows.length; var iteration = lastRow; var row = tbl.insertRow(lastRow); var box = row.insertCell(0); var element = document.createElement('input'); element.setAttribute('type', 'text'); element.setAttribute('name', 'startDate' + iteration); box.appendChild(element); } </script> --This code creates the text boxes properly, but I am not being able to add the datepicker to it. Please suggest me a way to add the datepicker to the textboxes in the dynamically generated rows. Thank You Regards Rusho Shaw Hi, I would just like to know how I would dynamically add another table once text fields in the existing table is clicked on. So pretty much what I have is a table with 5 textboxes lined up horizontally in the first row along with couple of buttons in the second row. What I want is that once one text box is clicked, another table like the one above is created and appears below that initial table. So this is the inital table that should be replicated on each click: Code: <table> <tr> <td><input type="text" /></td> <td><input type="text" /></td> <td><input type="text" /></td> <td><input type="text" /></td> <td><input type="text" ></td> </tr> <tr> <td><button /></td> <td><button /></td> </tr> </table> How would I go about achieving this? Thanks Hellooo. So I'm having trouble figuring out how to dynamically add another set of rows to a table when a button is clicked. The code below shows what goes into one set. When the button is clicked, it needs to create another three rows with the same format as the code below, but the variable names need to show what row they're on so I can easily call the values that have been inputed in another function that saves the information. Sooo for example the first variable, bhrs1-1 needs to become bhrs4-1 in the next set (because there's already a bhrs2-1 and bhrs3-1 in this set, which would become bhrs5-1 and bhrs6-1 in the new set). Sorry the code's so long! Help would be greatly appreciated. Thanksss!! Code: <TBODY> <INPUT TYPE=HIDDEN id=bhrs1-1 name=bhrs1-1><INPUT TYPE=HIDDEN id=comment1-1 name=comment1-1> <INPUT TYPE=HIDDEN id=bhrs1-2 name=bhrs1-2><INPUT TYPE=HIDDEN id=comment1-2 name=comment1-2> <INPUT TYPE=HIDDEN id=bhrs1-3 name=bhrs1-3><INPUT TYPE=HIDDEN id=comment1-3 name=comment1-3> <INPUT TYPE=HIDDEN id=bhrs1-4 name=bhrs1-4><INPUT TYPE=HIDDEN id=comment1-4 name=comment1-4> <INPUT TYPE=HIDDEN id=bhrs1-5 name=bhrs1-5><INPUT TYPE=HIDDEN id=comment1-5 name=comment1-5> <INPUT TYPE=HIDDEN id=bhrs1-6 name=bhrs1-6><INPUT TYPE=HIDDEN id=comment1-6 name=comment1-6> <INPUT TYPE=HIDDEN id=bhrs1-7 name=bhrs1-7><INPUT TYPE=HIDDEN id=comment1-7 name=comment1-7> <TR> <TD HEIGHT=20 SDVAL="1" SDNUM="1033;1033;#,##0_);[RED](#,##0)"> <SELECT style="width:500px;" name=project_id1 size=1 onChange='onProjectChanged(1);'> <? // // Load Projects // // $sresults = mysql_query("SELECT project_id, project, billable_rate, customer_id, Customer.CustomerName FROM Project LEFT OUTER JOIN Customer ON Project.customer_id=Customer.customer_id WHERE status_id='active' ORDER BY project"); $sresults = mysql_query("SELECT project_id, project, billable_rate, Project.customer_id, CostCenter.DisplayNameShort FROM Project LEFT OUTER JOIN CostCenter ON Project.customer_id=CostCenter.customer_id WHERE status_id='active' ORDER BY customer_id,CostCenter.DisplayNameShort,project"); // $srate = 0; print "<OPTION value='0'>--</OPTION>\n"; while($arow = mysql_fetch_assoc($sresults)) { // $srate = $arow["billable_rate"]; print "<OPTION value=\"" . $arow["project_id"] . "\">" . substr($arow["DisplayNameShort"], 0, 15) . ": " . $arow["project"] . "</OPTION>\n"; } // print "\n</SELECT>Billable Rate: <INPUT name=billable_rate value=\"" . $srate . "\" size=10 DISABLED></TD>\n"; ?> </TD> <TD> <SELECT name=task11 size=1 style="width:220px;" onChange='onTaskChange(1);'> <? print "<OPTION value='0'>--</OPTION>\n"; print "<OPTION value='1'>Sales Support</OPTION>\n"; print "<OPTION value='2'>Project Management</OPTION>\n"; print "<OPTION value='3'>Discovery and Requirements Documentation</OPTION>\n"; print "<OPTION value='4'>Analysis and Design</OPTION>\n"; print "<OPTION value='5'>Coding, Unit Testing, Infrastructure Changes</OPTION>\n"; print "<OPTION value='6'>QA, Planning, System Testing</OPTION>\n"; print "<OPTION value='7'>User Acceptance Testing</OPTION>\n"; print "<OPTION value='8'>User Documentation and Training</OPTION>\n"; print "<OPTION value='9'>Launch</OPTION>\n"; print "<OPTION value='10'>Maintenance, Support, Account Management</OPTION>\n"; ?> </TD> <TD SDNUM="1033;0;#,##0.0_);[RED]\(#,##0.0\)"> <P ALIGN=CENTER><INPUT id=hrs1-1 name=hrs1-1 size=2 maxlength=2 onFocus='onCellFocus(1,1);' onChange='calcRowTotal(1,1);'><BR> </P> </TD> <TD SDNUM="1033;0;#,##0.0_);[RED]\(#,##0.0\)"> <P ALIGN=CENTER><INPUT id=hrs1-2 name=hrs1-2 size=2 maxlength=2 onFocus='onCellFocus(1,2);' onChange='calcRowTotal(1,2);'><BR> </P> </TD> <TD SDNUM="1033;0;#,##0.0_);[RED]\(#,##0.0\)"> <P ALIGN=CENTER><INPUT id=hrs1-3 name=hrs1-3 size=2 maxlength=2 onFocus='onCellFocus(1,3);' onChange='calcRowTotal(1,3);'><BR> </P> </TD> <TD SDNUM="1033;0;#,##0.0_);[RED]\(#,##0.0\)"> <P ALIGN=CENTER><INPUT id=hrs1-4 name=hrs1-4 size=2 maxlength=2 onFocus='onCellFocus(1,4);' onChange='calcRowTotal(1,4);'><BR> </P> </TD> <TD SDNUM="1033;0;#,##0.0_);[RED]\(#,##0.0\)"> <P ALIGN=CENTER><INPUT id=hrs1-5 name=hrs1-5 size=2 maxlength=2 onFocus='onCellFocus(1,5);' onChange='calcRowTotal(1,5);'><BR> </P> </TD> <TD SDNUM="1033;0;#,##0.0_);[RED]\(#,##0.0\)"> <P ALIGN=CENTER><INPUT id=hrs1-6 name=hrs1-6 size=2 maxlength=2 onFocus='onCellFocus(1,6);' onChange='calcRowTotal(1,6);'><BR> </P> </TD> <TD SDNUM="1033;0;#,##0.0_);[RED]\(#,##0.0\)"> <P ALIGN=CENTER><INPUT id=hrs1-7 name=hrs1-7 size=2 maxlength=2 onFocus='onCellFocus(1,7);' onChange='calcRowTotal(1,7);'><BR> </P> </TD> <TD BGCOLOR="#ffff99" SDVAL="0" SDNUM="1033;0;#,##0.0_);[RED]\(#,##0.0\)"> <P ALIGN=CENTER><FONT SIZE=3><B><INPUT id=task1total size=2 maxlength=4 DISABLED></B></FONT> </P> </TD> </TR> <INPUT TYPE=HIDDEN id=bhrs2-1 name=bhrs2-1><INPUT TYPE=HIDDEN id=comment2-1 name=comment2-1> <INPUT TYPE=HIDDEN id=bhrs2-2 name=bhrs2-2><INPUT TYPE=HIDDEN id=comment2-2 name=comment2-2> <INPUT TYPE=HIDDEN id=bhrs2-3 name=bhrs2-3><INPUT TYPE=HIDDEN id=comment2-3 name=comment2-3> <INPUT TYPE=HIDDEN id=bhrs2-4 name=bhrs2-4><INPUT TYPE=HIDDEN id=comment2-4 name=comment2-4> <INPUT TYPE=HIDDEN id=bhrs2-5 name=bhrs2-5><INPUT TYPE=HIDDEN id=comment2-5 name=comment2-5> <INPUT TYPE=HIDDEN id=bhrs2-6 name=bhrs2-6><INPUT TYPE=HIDDEN id=comment2-6 name=comment2-6> <INPUT TYPE=HIDDEN id=bhrs2-7 name=bhrs2-7><INPUT TYPE=HIDDEN id=comment2-7 name=comment2-7> <TR> <TD HEIGHT=20 SDVAL="2" SDNUM="1033;1033;#,##0_);[RED](#,##0)"> <INPUT name=remove1 value=Remove type=button onClick='removeProject(1);'> </TD> <TD> <SELECT name=task12 size=1 style="width:220px;" onChange='onTaskChange(2);'> <? print "<OPTION value='0'>--</OPTION>\n"; print "<OPTION value='1'>Sales Support</OPTION>\n"; print "<OPTION value='2'>Project Management</OPTION>\n"; print "<OPTION value='3'>Discovery and Requirements Documentation</OPTION>\n"; print "<OPTION value='4'>Analysis and Design</OPTION>\n"; print "<OPTION value='5'>Coding, Unit Testing, Infrastructure Changes</OPTION>\n"; print "<OPTION value='6'>QA, Planning, System Testing</OPTION>\n"; print "<OPTION value='7'>User Acceptance Testing</OPTION>\n"; print "<OPTION value='8'>User Documentation and Training</OPTION>\n"; print "<OPTION value='9'>Launch</OPTION>\n"; print "<OPTION value='10'>Maintenance, Support, Account Management</OPTION>\n"; ?> </TD> <TD SDNUM="1033;0;#,##0.0_);[RED]\(#,##0.0\)"> <P ALIGN=CENTER><INPUT id=hrs2-1 name=hrs2-1 size=2 maxlength=2 onFocus='onCellFocus(2,1);' onChange='calcRowTotal(2,1);'><BR> </P> </TD> <TD SDNUM="1033;0;#,##0.0_);[RED]\(#,##0.0\)"> <P ALIGN=CENTER><INPUT id=hrs2-2 name=hrs2-2 size=2 maxlength=2 onFocus='onCellFocus(2,2);' onChange='calcRowTotal(2,2);'><BR> </P> </TD> <TD SDNUM="1033;0;#,##0.0_);[RED]\(#,##0.0\)"> <P ALIGN=CENTER><INPUT id=hrs2-3 name=hrs2-3 size=2 maxlength=2 onFocus='onCellFocus(2,3);' onChange='calcRowTotal(2,3);'><BR> </P> </TD> <TD SDNUM="1033;0;#,##0.0_);[RED]\(#,##0.0\)"> <P ALIGN=CENTER><INPUT id=hrs2-4 name=hrs2-4 size=2 maxlength=2 onFocus='onCellFocus(2,4);' onChange='calcRowTotal(2,4);'><BR> </P> </TD> <TD SDNUM="1033;0;#,##0.0_);[RED]\(#,##0.0\)"> <P ALIGN=CENTER><INPUT id=hrs2-5 name=hrs2-5 size=2 maxlength=2 onFocus='onCellFocus(2,5);' onChange='calcRowTotal(2,5);'><BR> </P> </TD> <TD SDNUM="1033;0;#,##0.0_);[RED]\(#,##0.0\)"> <P ALIGN=CENTER><INPUT id=hrs2-6 name=hrs2-6 size=2 maxlength=2 onFocus='onCellFocus(2,6);' onChange='calcRowTotal(2,6);'><BR> </P> </TD> <TD SDNUM="1033;0;#,##0.0_);[RED]\(#,##0.0\)"> <P ALIGN=CENTER><INPUT id=hrs2-7 name=hrs2-7 size=2 maxlength=2 onFocus='onCellFocus(2,7);' onChange='calcRowTotal(2,7);'><BR> </P> </TD> <TD BGCOLOR="#ffff99" SDVAL="0" SDNUM="1033;0;#,##0.0_);[RED]\(#,##0.0\)"> <P ALIGN=CENTER><FONT SIZE=3><B><INPUT id=task2total size=2 maxlength=4 DISABLED></B></FONT> </P> </TD> </TR> <INPUT TYPE=HIDDEN id=bhrs3-1 name=bhrs3-1><INPUT TYPE=HIDDEN id=comment3-1 name=comment3-1> <INPUT TYPE=HIDDEN id=bhrs3-2 name=bhrs3-2><INPUT TYPE=HIDDEN id=comment3-2 name=comment3-2> <INPUT TYPE=HIDDEN id=bhrs3-3 name=bhrs3-3><INPUT TYPE=HIDDEN id=comment3-3 name=comment3-3> <INPUT TYPE=HIDDEN id=bhrs3-4 name=bhrs3-4><INPUT TYPE=HIDDEN id=comment3-4 name=comment3-4> <INPUT TYPE=HIDDEN id=bhrs3-5 name=bhrs3-5><INPUT TYPE=HIDDEN id=comment3-5 name=comment3-5> <INPUT TYPE=HIDDEN id=bhrs3-6 name=bhrs3-6><INPUT TYPE=HIDDEN id=comment3-6 name=comment3-6> <INPUT TYPE=HIDDEN id=bhrs3-7 name=bhrs3-7><INPUT TYPE=HIDDEN id=comment3-7 name=comment3-7> <TR> <TD HEIGHT=20 SDVAL="3" SDNUM="1033;1033;#,##0_);[RED](#,##0)"> <P><BR> </P> </TD> <TD> <SELECT name=task13 size=1 style="width:220px;" onChange='onTaskChange(3);'> <? print "<OPTION value='0'>--</OPTION>\n"; print "<OPTION value='1'>Sales Support</OPTION>\n"; print "<OPTION value='2'>Project Management</OPTION>\n"; print "<OPTION value='3'>Discovery and Requirements Documentation</OPTION>\n"; print "<OPTION value='4'>Analysis and Design</OPTION>\n"; print "<OPTION value='5'>Coding, Unit Testing, Infrastructure Changes</OPTION>\n"; print "<OPTION value='6'>QA, Planning, System Testing</OPTION>\n"; print "<OPTION value='7'>User Acceptance Testing</OPTION>\n"; print "<OPTION value='8'>User Documentation and Training</OPTION>\n"; print "<OPTION value='9'>Launch</OPTION>\n"; print "<OPTION value='10'>Maintenance, Support, Account Management</OPTION>\n"; ?> </TD> <TD SDNUM="1033;0;#,##0.0_);[RED]\(#,##0.0\)"> <P ALIGN=CENTER><INPUT id=hrs3-1 name=hrs3-1 size=2 maxlength=2 onFocus='onCellFocus(3,1);' onChange='calcRowTotal(3,1);'><BR> </P> </TD> <TD SDNUM="1033;0;#,##0.0_);[RED]\(#,##0.0\)"> <P ALIGN=CENTER><INPUT id=hrs3-2 name=hrs3-2 size=2 maxlength=2 onFocus='onCellFocus(3,2);' onChange='calcRowTotal(3,2);'><BR> </P> </TD> <TD SDNUM="1033;0;#,##0.0_);[RED]\(#,##0.0\)"> <P ALIGN=CENTER><INPUT id=hrs3-3 name=hrs3-3 size=2 maxlength=2 onFocus='onCellFocus(3,3);' onChange='calcRowTotal(3,3);'><BR> </P> </TD> <TD SDNUM="1033;0;#,##0.0_);[RED]\(#,##0.0\)"> <P ALIGN=CENTER><INPUT id=hrs3-4 name=hrs3-4 size=2 maxlength=2 onFocus='onCellFocus(3,4);' onChange='calcRowTotal(3,4);'><BR> </P> </TD> <TD SDNUM="1033;0;#,##0.0_);[RED]\(#,##0.0\)"> <P ALIGN=CENTER><INPUT id=hrs3-5 name=hrs3-5 size=2 maxlength=2 onFocus='onCellFocus(3,5);' onChange='calcRowTotal(3,5);'><BR> </P> </TD> <TD SDNUM="1033;0;#,##0.0_);[RED]\(#,##0.0\)"> <P ALIGN=CENTER><INPUT id=hrs3-6 name=hrs3-6 size=2 maxlength=2 onFocus='onCellFocus(3,6);' onChange='calcRowTotal(3,6);'><BR> </P> </TD> <TD SDNUM="1033;0;#,##0.0_);[RED]\(#,##0.0\)"> <P ALIGN=CENTER><INPUT id=hrs3-7 name=hrs3-7 size=2 maxlength=2 onFocus='onCellFocus(3,7);' onChange='calcRowTotal(3,7);'><BR> </P> </TD> <TD BGCOLOR="#ffff99" SDVAL="0" SDNUM="1033;0;#,##0.0_);[RED]\(#,##0.0\)"> <P ALIGN=CENTER><FONT SIZE=3><B><INPUT id=task3total size=2 maxlength=4 DISABLED></B></FONT> </P> </TD> </TR> </TBODY> So I have been struggling with a Javascript issues for a couple of days now and can't find an answer anywhere online that has helped. I have a javascript loop that is looping through all of my <dfn> html tags. These tags are used to show a glossary term on my page. When the user mouses over the term it shows a popup with the term name and the definition. Here is my javascript function: Code: function definitionRollover(){ var j; var dfns = document.getElementsByTagName('dfn') for (j=0; j<dfns.length;j++){ var term = dfns[j].innerHTML.charAt(0).toUpperCase() + dfns[j].innerHTML.slice(1); var definitionArray = new Array(term, dfns[j].title); dfns[j].onmouseover = function(){stm(definitionArray,Style[0])} dfns[j].onmouseout = function(){htm();}; } } As you can see I am adding a onmouseover event to these <dfn> tags which calls another function (stm) with the definition and term being held in the definitionArray. This works great until I have multiple terms on a page. When I have multiple terms it only shows the last terms definition for all terms. My question is how I can get it to work for all terms. I know that throughout the loop the definitionArray is holding the correct info at the correct time but for some reason it only shows the last one. I hope that this makes sense and if anyone could give me any tips or leads it would be very much appreciated. Hello, I want to add rows and columns on click. So, i have a table with columns and rows and I had a add and remove button. So I want the user to be able to add/remove more rows if they have multiple inputs/outputs. So what I want is when the user clicks on add.png, I want another row of Input and Description to appear underneath the current one. Here is my code.. Code: <img src="images/add.png" width="15" height="15" align="right" > <div class="open"> <table width="200" border="0"> <tr> <td class="propertyCol">Input: </th> <td class="propertyCol"><input class="text ui-widget-content ui-corner-all" value="" style="width:210px"></input></th> <td class="propertyCol">Description: </th> <td class="propertyCol"><textarea name="" cols="45" rows="1" class="text ui-widget-content ui-corner-all"></textarea> </th> <td class="propertyCol"><a href="javascript:removeElement();" ><img src="images/remove.png" alt="" width="15" height="15" /></a> </th> </tr> </table> <table width="200" border="0"> <tr> <td class="propertyCol">Output: </th> <td class="propertyCol"><input class="text ui-widget-content ui-corner-all" style="width:200px"></input></th> <td class="propertyCol">Description: </th> <td class="propertyCol"><textarea name="" cols="45" rows="1" class="text ui-widget-content ui-corner-all"></textarea> </th> <td class="propertyCol"><a href="javascript:removeElement();" ><img src="images/remove.png" alt="" width="15" height="15" /></a> </th> </tr> </table> </div Hello, I am trying to get something to work and I am not having any luck. I want to dynamically add a set of fields to a table when when the user onBlur the selection drop-down. I want the cursor to be in the text field of the newly added set. I have been playing around with onfocus function on the hyperlink to see if when focus is gained, it would throw the user into the text field. I am getting the impress that the field has not been created yet, so the getElementbById function cannot find the object just recently created. Code: <!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> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title></title> <script language="JavaScript"> function addEvent() { var ni = document.getElementById('myDiv'); var numi = document.getElementById('theValue'); var num = (document.getElementById("theValue").value -1)+ 2; numi.value = num; var divIdName = "my"+num+"Div"; var newdiv = document.createElement('div'); newdiv.setAttribute("id",divIdName); newdiv.innerHTML = '<div>'+ num +'</div><div class=name><input class=name id=item-' + num + ' type=text name=item-'+ num + '></div><div><select name=selRow-' + num + ' onBlur="addEvent();"><option value="0">Check</option><option value="1">Cash</option><option value="2">Money Order</option><option value="3">EFT</option></select></div>'; ni.appendChild(newdiv); } function setTxtFocus() { var ni = document.getElementById('myDiv'); var numi = document.getElementById('theValue'); var num = (document.getElementById("theValue").value -2)+ 2; document.getElementById('item-' + num).focus; } </script><style type="text/css"> @import url(style.css); </style> </head> <body onload="addEvent();"> <div id=image></div> <form action=process.php method=post> <input type="hidden" value="0" id="theValue" /> <div id="myDiv"></div> <p><a href="javascript:;" onclick="setTxtFocus();">Add Other Suggestion</a></p> <p><input type=submit id="submitbutton" value=Submit disabled> <INPUT TYPE="button" VALUE="Back" onClick="history.go(-1);return true;"></p> </form> </body> </html> Thanks jlimited Hi Experts, i'am able create dynamically 2 text boxes ( start date & End Date) . Also i am able to create dynamically (img) calendar gif pictures beside each textbox. What i am stuck on is how to popup a calendar while clicking on the img and assign the date to a dynamic texboxes... Any help is much appreciated.. thank you here is the part of my code : // Create Start Date Text box var newStartDate = document.createElement('input'); newStartDate.setAttribute("type","date"); newStartDate.size=8; // Create calendar 1 img var newCalImg1 = document.createElement('img'); newCalImg1.src = "../media/forms/cal.gif"; // Create End Date Text box var newEndDate = document.createElement('input'); newEndDate.size=8; // Create calendar2 img var newCalImg2 = document.createElement('img'); newCalImg2.src = "../media/forms/cal.gif"; Hi Peers, i have a button that helps me creating more than one dynamic text box and dropdownlist... how it possible to capture the values in those dynamic comtrols ? i am trying the following but did not work ..when the code is excuted it gives me [object] // Create Text box 1 var newStartDate = document.createElement('input'); newStartDate.setAttribute("type","date"); newStartDate.size=8; //capture the value in a temp variable val1 var val1 = document.getElementsByName(newStartDate); alert(val1); the alert gives [object] thanks Is it possible to dynamically change the value of text on a page as the user types into a text box? E.g. like: You Are Typing: <script> var keyword = document.getElementById('string'); document.write(keyword); </script> Or I could probably insert it into a function and loop it over and over again or is there a better way? I'm using Kevin Roth's Cross-Browser Rich Text Editor JS component. Below is a demo.php script showing how it's created in JS. I got it working fine but I now want to dynamically add new text to the component in my php script. I know how to setup the php part to initiate the new text load event but I can't figure out how to actually get the new text into the RTE component inside a JS function. I tried this JS function but it didn't load in the new text in: PHP Code: function pre_canned_message_click() { rte1.html = 'New string'; } In the demo.php below the RTE component is loaded the same way rte1.html = but in the JS function it doesn't work. I don't know what I'm missing here. Thanks for any help... PHP Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <?php echo var_dump($_POST); ?> <!-- // Cross-Browser Rich Text Editor // Written by Kevin Roth (http://www.kevinroth.com/rte/) // License: http://creativecommons.org/licenses/by/2.5/ //--> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <title>Cross-Browser Rich Text Editor (RTE)</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> <meta name="keywords" content="cross-browser rich text editor, rte, textarea, htmlarea, content management, cms, blog, internet explorer, firefox, safari, opera, netscape, konqueror" /> <meta name="description" content="The cross-browser rich-text editor (RTE) is based on the designMode() functionality introduced in Internet Explorer 5, and implemented in Mozilla 1.3+ using the Mozilla Rich Text Editing API." /> <meta name="author" content="Kevin Roth" /> <meta name="ROBOTS" content="ALL" /> <!-- html2xhtml.js written by Jacob Lee <letsgolee@lycos.co.kr> //--> <script language="JavaScript" type="text/javascript" src="../cbrte/html2xhtml.min.js"></script> <script language="JavaScript" type="text/javascript" src="../cbrte/richtext_compressed.js"></script> </head> <body> <h2>Cross-Browser Rich Text Editor (RTE) Demo</h2> <p>For more information, visit the <a href="http://www.kevinroth.com/rte/">Cross-Browser Rich Text Editor (RTE) home page</a>.</p> <!-- START Demo Code --> <form name="RTEDemo" action="demo.php" method="post" onsubmit="return submitForm();"> <script language="JavaScript" type="text/javascript"> <!-- function submitForm() { //make sure hidden and iframe values are in sync for all rtes before submitting form updateRTEs(); return true; } //Usage: initRTE(imagesPath, includesPath, cssFile, genXHTML, encHTML) initRTE("../cbrte/images/", "../cbrte/", "", true); //--> </script> <noscript><p><b>Javascript must be enabled to use this form.</b></p></noscript> <script language="JavaScript" type="text/javascript"> <!-- //build new richTextEditor var rte1 = new richTextEditor('rte1'); <?php //format content for preloading if (!(isset($_POST["rte1"]))) { $content = "here's the " . chr(13) . "\"preloaded <b>content</b>\""; $content = rteSafe($content); } else { //retrieve posted value $content = rteSafe($_POST["rte1"]); } ?> rte1.html = '<?=$content;?>'; //rte1.toggleSrc = false; rte1.build(); //--> </script> <p><input type="submit" name="submit" value="Submit" /></p> </form> <?php function rteSafe($strText) { //returns safe code for preloading in the RTE $tmpString = $strText; //convert all types of single quotes $tmpString = str_replace(chr(145), chr(39), $tmpString); $tmpString = str_replace(chr(146), chr(39), $tmpString); $tmpString = str_replace("'", "'", $tmpString); //convert all types of double quotes $tmpString = str_replace(chr(147), chr(34), $tmpString); $tmpString = str_replace(chr(148), chr(34), $tmpString); // $tmpString = str_replace("\"", "\"", $tmpString); //replace carriage returns & line feeds $tmpString = str_replace(chr(10), " ", $tmpString); $tmpString = str_replace(chr(13), " ", $tmpString); return $tmpString; } ?> <!-- END Demo Code --> </body> </html> Hi Guys, I am new to this forum,based on the combobox value,I am creating a textboxes dynamically in jsp .Based on the count of textboxe's the textarea content comes with <value1> like this... Here i tried like this, <html> <head> <script> function copy_data(val,id,textareaValue){ var enteredText = val; alert("enteredText -----------"+enteredText); var boxId= id; alert("boxId-----------"+boxId); var textValue= textareaValue; alert("textValue-----------"+textValue); var beforeBrac = textValue.substring(0,textValue.indexOf("<")); alert("beforeBrac -----------"+beforeBrac ); var inbracket = textValue.substring(beforeBrac.length+1,textValue.indexOf(">")); alert("inbracket -----------"+inbracket); if(boxId = "1"){ inbracket = val; } alert("inbracket -----------"+inbracket); var afterBrac = textValue.substring(textValue.indexOf(">"),textValue.length); alert("afterBrac -----------"+afterBrac ); var fstr = beforeBrac +"<"+inbracket +afterBrac ; if(boxId == "1"){ document.getElementById('txtArea').value = fstr; alert("final str value is"+fstr); } } </script> </head> <body> <input type="text" name ="a" id="1" onkeyup="copy_data(this.value,this.id,document.getElementById('txtArea').value)"/> <input type="text" name ="a" id="2" onkeyup="copy_data(this.value,this.id, document.getElementById('txtArea').value)"/> <textarea rows="2" cols="20" id="txtArea"> At W3Schools you <will> find all <the> Web-building tutorials <you> need, from basic HTML to advanced <XML>, SQL, ASP, and PHP. </textarea> </body> </html> three text boxes with some value [ value1 ] [value2] [value3 ] this is the text area content:- At W3Schools you <will> find all <the> Web-building tutorials <you> need, from basic HTML to advanced XML, SQL, ASP, and PHP. the output should be :- At W3Schools you <value1> find all <value2> Web-building tutorials <value3 > need, from basic HTML to advanced XML, SQL, ASP, and PHP... But i can't get it exactly..When i enter or delete the value it should replaced in the proper <> correctly.. If i enter the value in 1st textbox it should replace the value 1st <>.same for others also...Any Idea's ?Plz suggest me ... Hello all, I am doing a website project and in that currently I am designing a product page. I have to design add values to text boxes and drag and drop the text boxes in the workspace and delete the text boxes the user does not want and have to draw a graphical line between the text boxes which are in order. I have designed and coded everything except the graphical line part. I am a learner in javascript and Can we draw a graphical line dynamically between the text boxes in the webpage? If we can draw, can anyone let me know the tutorial for that so that I can learn and start coding as I have to submit that project soon. Thank you. I'm creating sort of a chat with images, the problem is, when i am adding new data to the DIV (either if it's blank or a new message), it also refreshes the old data, therefore the images are being reloaded. Code: document.getElementById("chatwindow").innerHTML += new_data; I want to add that new data without having the entire "innerHTML" of that div being replaced. Hey all, I'm sure this is very basic but I'm having a hard time adding a hyperlink to text within javascript. I want to add a website link to the text 'click here' that is being displayed under the image within javascipt. I end up modifying the whole image instead, removing the javascript that displays the larger version of the image. Can anyone help me out please? Here's the coding. I'm using Dreamweaver CS5 on a PC to modify a few things and using another website building program to get the basic layout. I'm just a small business owner trying to get my website off the ground. Thanks in advance! <div id="imCel1_01"> <div id="imCel1_01_Cont"> <div id="imObj1_01"> <a href="javascript:imShowBox('files/june2011.jpg',500,500,'Right click to print....................Click HERE for website!','IMG','t');" title=""><img src="images/p025_1_01.jpg" alt="" title="" /></a> </div> Hey guys, I just joined the forums (literally) and just started coding (mainly with CSS and HTML) about 3-4 weeks ago. I'd really like to get into JavaScript to make cool things happen on my website. With that being said, I've come up with a pretty cool idea but am not sure how to go about my problem. Enough with the chit chat. What I'm trying to do is add text to a user's input. For instance, if they write "Hello", the function should automatically add "World" to the output. I'd ideally like for the output to be searched on Google (think search engine) with the results displayed on a new page. Thanks in advance for any help! Sup yo, I need to add text in a <textarea>, but i can only append text at the end. Is there any way to add text to where the cursor is currently at? Code: function addCharm(var1) { var newtext = var1; document.lolform.inputtext.value += newtext; } And below i has sum buttonz that uses that function. So, again, how can I add text to where the I-beam is currently, instead of at the end? Thanks in advance. Hey guys, I have a script which adds more text fields to a div in a form, but when it adds a new field the text in the others is cleared. :S http://martynleeball.goodluckwith.us/ PHP Code: <!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> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Draw Somthing - Word Guess</title> <script type="text/javascript"> function add_field(obj, count) { //Count how many fields there is so the correct number can be added to the ID var form_name = document.getElementById(obj); var inputs = form_name.getElementsByTagName('input'); var g = 1; //alert("Container: " + obj + ". Inputs: " + inputs.length); for ( var i = 0; i < inputs.length; i++) { var node = inputs[i]; if (node.getAttribute('type') == 'text') { g++; } } //Field to add to the form if (!count) { if (g < 9) { var text_field_html = "<input type=\"text\" id=\"input" + g + "\" name=\"input" + g + "\" /><input type=\"button\" value=\"X\" onClick=\"remove_field(\'text_field_container\', this)\" id=\"close" + g + "\"/>"; form_name.innerHTML += text_field_html + "<br id=\"br_" + g + "\" />"; } } } function remove_field(parent_id, r_obj) { var parent = document.getElementById(parent_id); var child = document.getElementById(r_obj.id); var num = r_obj.id.charAt(r_obj.id.length-1); var child2 = document.getElementById('input' + num); var child3 = document.getElementById("br_" + num); parent.removeChild(child); parent.removeChild(child2); parent.removeChild(child3); } </script> </head> <body> <br /> <form id="add_words" action="test.php" method="post"> <div id="text_field_container"> <input type="text" id="input1" name="input1" /><input type="button" value="X" id="close1" onClick="remove_field('text_field_container', this)"/> <br id="br_1" /> </div> <input type="button" value="Add more..." onclick="add_field('text_field_container')" /> <input type="submit" value="Submit" onclick="" /> </form> </body> </html> I have a text field, call it income, that when the input is > 0 I need to dynamically show the next text box, and if it is blank hide the next text box. I would like to use onBlur but can't seem to get it to work. Can I do this? Help ok i have a script which will make a copy of the html in a div and place it into another div the problem with this it creates a duplicate element with the same id so what i want to know is can i create a new id based off old ids using a generic type script Code: function scope(e) { var popin = document.getElementById('popin'); popin.innerHTML = "<div class='container'>"+e.innerHTML+"</div>"; popin.style.display = "block"; } this code is designed for taking content in a small div and placing it into a larger div to increase the viewing area so what i would need is sumthing that can look for Code: id="sum text" and maybe amend it to Code: id="sum textP" or sumthing to that extent if sum1 could point me in the right direction that would be great if my post is not clear enough just ask me to be more specific or sumthing and i will see what i can do to try and make it more clear if needed |