JavaScript - Null In $_post That Created By Javascript In Form Element
I have created a form with javascript embedded to dynamically assign value to
Code:
document.myForm.myTextBox.value based on user inputs, and when submitting the form, the targeted php file will process the data and records them in MySQL. The problem is that the value of myTextBox remains 'null' even when the javascript assigns a value to it (and it is visible in the form). Here is the code of the javascript: Code: document.register.street.value = http.responseText.split('^')[0]; document.register.city.value = http.responseText.split('^')[1]; document.register.street.disabled = true; document.register.city.disabled = true; To prevent user-mistyping, the textbox will be disabled after the value is set. I tried to search but I found it is very difficult when I don't even know what key word to use to describe this issue. I hope anyone can help me with this here, and thanks for any inputs. Similar TutorialsHi, I have a form in which I preset some text inside a readonly, disabled textarea using javascript ('data' being the text): document.getElementById("link_of_current_view2").value = data; However, once I call my .php script to process the form, the element is null. How do I get it to pass along that data, which is in the textbox when the user views the form? Code: <div id="sendlink" class="contact_form" style="z-index:10;"> <a class="close" onclick="document.sendlink_form.reset();return false">CLOSE</a> <form id='sendlink_form' name='sendlink_form' method="post" action="sendlink.php" > <label for="link_of_current_view2">Link: </label> <textarea id="link_of_current_view2" name="_of_current_view2" class="link_of_current_view" rows="2" disabled="disabled" wrap="soft" size="58" value="" readonly="readonly" value=/></textarea> <input type="image" src="images/forms/submit.png" value="Submit" alt="Submit"> <a onclick="javascript:reset_sendlink()" style="cursor:pointer"><img src="images/forms/reset.png"></a> </div> Thanks for reading! never mind
I'm trying to understand how forms, data, php, javascript all work together. So 1) I hardcoded some html form fields with values using php using "echo", then 2) I dynamically created some more html form fields with values using javascript using "createElement" and appending to the html form element. When I click on the submit form, the php created form fields still show on the webpage, but the javascript dynamically created form fields disappear. Can anyone shed some light for me? Why are the javascript created form fields disappearing when I click on submit and not the PHP created form fields? Thank you! Code: <form method="post" id="commentform" action="<?php echo $PHP_SELF?>"> Hello, I have the following DIV tag Code: <div id = "cbContainer"> </div> The div is initially hidden as the display is set to none. I have one text input in my form. Depending upon the changed text in that textbox, there is a javascript function which creates a list of checkboxes and by using the innerHTML, the above div is filled up with the check boxes like shown in the code below: Code: var chkboxes = ''; for(var r = 0; r < related.length; r++) { chkboxes = chkboxes + '<div class ="versionswidth">'+ '<input type="checkbox" name="version" value = related[r] />'+ related[r] + '</div>'; } var div = document.getElementById("cbContainer"); div.innerHTML = chkboxes; div display is then set as "block" which makes the div visible. The problem is that on form submission, the input of selected checkboxes is not submitting. I will be grateful for any help. Thank you. I'm trying to check to see if a dynamically created element exists BEFORE creating another element of the same exact type...but my if statement at the beginning is not working and another element is just created. Code: function writeElement(id) { if(document.getElementsByTagName('transElement')[0]) { var id = id; killElement(); writeElement(id); } var id = id; var transElement = document.createElement('transElement'); var solidElement = document.createElement('solidElement'); var closeElement = document.createElement('closeElement'); //transElement.id = "transElement"; transElement.setAttribute('id', 'transElement'); solidElement.setAttribute('id', 'solidElement'); closeElement.setAttribute('id', 'closeElement'); closeElement.setAttribute('onClick', 'killElement()'); closeElement.innerHTML = "Close"; var content = "inject_poem.php?id=" + id; getdata(content, 'solidElement'); document.body.appendChild(transElement); document.body.appendChild(solidElement); document.body.appendChild(closeElement); } Does anyone know what is incorrect about my if statement? Hi people, I'm a novice in javascript and have no clue how to get get the following logic through in a form. Any help will be greatly appreciated. I have searched the forums and looked at a few similar script but can't make out head and tail of it Sorry if this is a oft repeated question. Here is the form I need, the post method is email : Name (txtfield) DOB (Date) Address (txtarea) Programme (Select list) : Options : Programme1, Programme2, Programme3 Date (Select list) : options : 10/10/2009 to 12/09/2009 15/10/2009 to 16/10/2009 Venue : Mainland Harvey Waterloo Time : 9am - 12 noon 1 pm - 3 pm 3 pm - 5 pm Here is the Logic : Date : Conditions If Programme1 is selected then date options 10/10/2009 to 12/09/2009 and 15/10/2009 to 16/10/2009 should both be selectable. If Programme2 is selected then date options 10/10/2009 to 12/09/2009 and 15/10/2009 to 16/10/2009 should both be selectable. If Programme3 is selected then date option 15/10/2009 to 16/10/2009 should auto selected and greyed out so that user don't have to select this. Venue : Conditions If Programme = Programme1 then all the venues should be selectable. If Programme = Programme2 and date = 10/10/2009 to 12/09/2009 then all the venues should be selectable. If Programme = Programme2 and date = 15/10/2009 to 16/10/2009 then only venues Harvey and Waterloo should be selectable. If Programme = Programme3 and date = 15/10/2009 to 16/10/2009 then only venue Waterloo should be selectable.... in fact venue Waterloo should be auto selected and greyed out so that user cannot change it. Time :Conditions : Always should be default selection and greyed out If Programme = Programme1 and venue is any one of Mainland, Harvey, Waterloo then the time should default to 9 am - 12 noon. If Programme = Programme2, Date = 10/10/2009 to 12/09/2009 and venue is any one of three then, the time should default to 1 pm - 3 pm. If Programme = Programme2, Date = 15/10/2009 to 16/10/2009 and venue is one of Harvey or Waterloo then the time should default to 1 pm - 3 pm If Programme = Programme3, Date = 15/10/2009 to 16/10/2009 and venue = Waterloo then the default time should be 3 pm to 5 pm Sorry for the long post and so many conditions. I'm trying to get a hang of how to go about doing this. This looks a pretty complicated logic but if you can point me in the right direction I'm sure I will get my head around this. Thanks for having a look and thanks in advance for any help. Cheers Can anyone tell why IE does not handle this form submit properly? Instead of going to the action of the form in formString, it just refreshes the page. Works fine in Firefox and Chrome. Code: Here is how the form is placed on the page and then submitted: document.getElementById('crtDiv').innerHTML = formString; document.getElementById('crtForm').submit(); Here is an example of how the formString is built: formString = "<form action='https://www.paypal.com/cgi-bin/webscr' method='POST' id='crtForm'>"; formString += BUNCH O INPUTS formString += "</form>"; I'm teaching myself JavaScript and created this animated countdown... I want to learn more advanced techniques, or shorthand code. If you see anything I can improve here or something that may not be suitable for a certain browser, please let me know... 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>History Countdown</title> <style> * { margin: 0; padding:0; } p { font-size: 1em; color: white; position: absolute; left: 450px; } #insertHere { background-color: #000; padding: 10px; width: 300px; height: 40px; position: relative; } #list { border: solid black 3px; height: 700px; width: 320px; } h3 { text-align: center; padding-top: 10px; padding-bottom: 10px; } form { text-align: center; } </style> <script> function gogo(){ var number = 2011; document.getElementById('formArea').innerHTML = ""; var pixelCount = 450; var intervalCount = 0; var opacityValue = 0; var pixels = 65 var ems = 1; var beginCount = setInterval(countDown, 1000) function countDown() { if(number==0){ clearInterval(beginCount); clearInterval(mover); alert ("done"); } intervalCount = 0; pixelCount = 450; pixels = 65; ems = 1; var opacityValue = 0; var mover = setInterval(moveNumber, 35); function moveNumber() { intervalCount += 1; if (intervalCount <= 12) { pixelCount -= pixels; opacityValue += .1; document.getElementById('para').style.left = pixelCount + "px" document.getElementById('para').style.opacity = opacityValue; document.getElementById('para').style.fontSize = ems + "em"; ems = ems + .1; pixels = pixels - 7; if (intervalCount == 2) { document.getElementById('para').innerHTML= number; number -= 1; } }//end if else if (intervalCount == 13) { clearInterval(mover); } } }//moveNumber } </script> </head> <body> <div id="list"><div id="insertHere"><p id="para"></p><span id="done"></span></div> <h3>History Countdown</h3> <div id="formArea"> <form> <input type="button" value="Start" id="goButton" onclick="gogo()" /> </form> </div> </div> </body> </html> Good Morning people, here is my problem, I have seen Java before but never really understood it, I have created a drawing from visio 2010 and published it as a web page that creates java scripts etc, the idea of the drawing is to be a "computer locator" the 2 problems that I have is that I want the shape to change color when located (hightlighted) and the second part is to disabe ctrl+click to access the hyperling that runs the command (which might be a IE8 thing not java??) here is the script I think I need to change to highlight the shape Code: function FindOnClick() { var count, indexOfString; var fieldsToSearchArray = new Array(); if (parent.xmlData != null && document.theForm[strProps + strChkBox].checked) { for( count=0; count < document.theForm.length; count++ ) { indexOfString = document.theForm[count].name.indexOf(strPropChkBox); if( -1 != indexOfString && document.theForm[count].checked ) { fieldsToSearchArray[ fieldsToSearchArray.length ] = document.theForm[count].name.slice(0, indexOfString); } } } var searchTokensArray = CreateSearchTokens (document.theForm.findString.value); if (searchTokensArray.length > 0) { var findArray = Find(searchTokensArray, fieldsToSearchArray); var ArrayLength = findArray.length; var strResultsHTML = "No matches found."; var lastPageID = null; var shapeID; if(ArrayLength > 0) { strResultsHTML = strResults + ' <b>'+ parent.HTMLEscape(document.theForm.findString.value) +'</b>'; for ( count = 0; count < ArrayLength; count++) { if( lastPageID != findArray[count].PageID ) { lastPageID = findArray[count].PageID; } shapeID = findArray[count].ShapeID; strResultsHTML += '<p class="results"><a href="javascript:populateSearchResultDetails(\'results_'+ lastPageID +'_'+ shapeID +'\', '+ lastPageID +','+ shapeID +'); TogglePlus(\'results_' + lastPageID + '_' + shapeID + '\',\'img_' + lastPageID + '_' + shapeID + '\', hideResults)"><img src="plus.gif" style="padding-left:13px" alt="Barrie Changed this" width="13" height="9" border="0" id="img_'+ lastPageID +'_'+ shapeID +'"></a>\n' strResultsHTML += '<a class="blu1" href="JavaScript:FindQuerySelect('; strResultsHTML += findArray[count].PageID + ","; strResultsHTML += findArray[count].ShapeID + ","; strResultsHTML += findArray[count].PinX + ","; strResultsHTML += findArray[count].PinY; strResultsHTML += ')">'+ findArray[count].Title +'</a></p>\n' strResultsHTML += '</div>\n'; strResultsHTML += '<div class="indent" id="results_'+ lastPageID +'_'+ shapeID +'" style="display:none;width:90%;"></div>\n' } } var divAdvSrch = document.getElementById("hideAdvSrch"); var imgAS0 = document.getElementById("as0"); var tmpObj = document.getElementById("hideResults"); if( tmpObj != null ) { tmpObj.innerHTML = strResultsHTML; tmpObj.open = "true"; tmpObj.style.display = "block"; any help would be very much appricated __________________ Barrie Willyouhelpmefixmykeyboard?Thespacebarisbroken! Hi, 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 php has the $_POST GLOBAL that contains an array of all the POST form variables. Does Javascript contain something similar built in?
I am not very experienced at javascript. Having trouble with some I used for a google map on some of the pages on company site. Appreciate any assistance someone out there could give. If you go to http://www.ghd.com/global/locations/...nsland/cairns/ you can see the error. Get the debug message: an error occurred on this page: Line: 74 Character: 9 Error: GetElementById(....)' is null or not an object The map is actually in a i frame For some reason in ie 6 this script error is popping up when the page loads, but does not when not shown within a iframe http://www.ghd.com/map/cazenovia.html Hi I am using a custom form elements script in the link below: www_bristolstreet_co_uk/page/find_a_dealer.htm and an error for null object is appearing from this line: active = option[0].childNodes[0].nodeValue; Can anyone please help? I am a novice at Javascript but got this script working perfectly on my local machine - once I loaded it the live site it didn't work... any advice would be greatly appreciated. Hello I am using a timer which goes down from 2 minutes to zero when 'jsp' is called. Timer is written in javascript. I am getting an error that document.form1.timerMin.value=<%=min%> is null or not an object. Here is the code (t.jsp): <% /* Default timer */ int min = 2; int sec = 5; /* Check for timer params */ try { String timerMin = request.getParameter("timerMin"); if (timerMin==null)timerMin=""; if (timerMin != null) { min = Integer.parseInt(timerMin); } String timerSec = request.getParameter("timerSec"); if (timerSec==null)timerSec=""; if (timerSec != null) { sec = Integer.parseInt(timerSec); } } catch(Exception m) { System.out.println("generated exception..............:"+m); } %> <script language="JavaScript" type="text/javascript"> <!-- /* Initialise timer */ var min = <%=min%>; // set the minutes var sec = <%=sec%>; // set the seconds function countDown() { sec--; if (sec == -1) { sec = 59; min--; } /* Write timer state to hidden form fields */ document.form1.timerMin.value=<%=min%> document.form1.timerSec.value=<%=sec%>; time = (min<=9 ? "0" + min : min) + " min and " + (sec<=9 ? "0" + sec : sec) + " sec "; document.getElementById('theTime').innerHTML = time; SD=window.setTimeout("countDown()", 1000); if (min == 0 && sec == 0) { window.clearTimeout(SD); } } window.onload = countDown(); --> </script> <style type="text/css"> <!-- .timeClass { font-family:arial,verdana,helvetica,sans-serif; font-weight:normal; font-size:10pt; } --> </style> <table width="100%"> <tr><td width="100%" align="right"> <span id="theTime" class="timeClass"></span> </td></tr> <form method="post" name="form1" id="form1" action="t.jsp" <td width="50%" valign="middle"> <input type="hidden" name="timerMin" value="<%=min%>"> <input type="hidden" name="timerSec" value="<%=sec%>"> <div align="center"><a href="javascript:form1.submit()" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image3','','/lms/images/submit_0.gif',1)"><img name="Image3" border="0" src="/lms/images/submit_0.gif" width="70" height="30"></a></div> </td> </form> Looking forward for an early reply. Thanks Hi I have the below page. When form is submitted by clicking on the button the function checkform() is executed. Problem is that I am getting a 'entrystartday' is null or not an object error on line Code: if (frm.entrystartday.value == 31) { What is the problem and how can I fix it? Thanks Regards Code: <html> <head> <title>test</title> </head> <body> <form id="theform" action="main.asp" method="post" onsubmit="return checkform()"> <table style="width: 477px;"> <tr> <td style="vertical-align: top;" class="boldwhite"> Start Date </td> <td> <select id="entrystartday" name="entrystartday"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> <option value="11">11</option> <option value="12">12</option> <option value="13">13</option> <option value="14">14</option> <option value="15">15</option> <option value="16">16</option> <option value="17">17</option> <option value="18">18</option> <option value="19">19</option> <option value="20">20</option> <option value="21">21</option> <option value="22">22</option> <option value="23">23</option> <option value="24">24</option> <option value="25">25</option> <option value="26">26</option> <option value="27">27</option> <option value="28">28</option> <option value="29">29</option> <option value="30">30</option> <option value="31">31</option> </select> / <select id="entrystartmonth" name="entrystartmonth"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> <option value="11">11</option> <option value="12">12</option> </select> / <select name="entrystartyear"> <option value="2010">2010</option> <option value="2011">2011</option> <option value="2012">2012</option> <option value="2013">2013</option> <option value="2014">2014</option> <option value="2015">2015</option> <option value="2014">2016</option> <option value="2015">2017</option> </select> <span class="style1"><strong><= Select correct Start Date</strong></span> </td> </tr> </table> <table> <tr> <td class="style2"> <input type="submit" value="save" name="submit" /> </td> </tr> </table> <input type="hidden" name="view" value="<% = theview%>" /> <input type="hidden" value="save" name="a" /> <input type="hidden" value="<% = dateview %>" name="dateview" /> </form> <script type="text/javascript"> function checkform() { document.write("<P>right now 1: " + new Date() + "<P>"); var frm = document.forms["theform"]; if (frm.entrystartday.value == 31) { alert('I am here'); }; document.write("<P>right now 2: " + new Date() + "<P>"); }; </script> </body> </html> Hello, I hope you can help me, I have used a really simple image script which features 3 thumbnails, you click one thumbnail and it loads the image as a larger image. Works perfectly in Google Chrome, Firefox - and then I've come to try in IE8... works perfect BUT javascript error as follows: - Webpage error details User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; GTB6.6; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; MDDC; InfoPath.2; .NET4.0C) Timestamp: Fri, 31 Dec 2010 17:14:48 UTC Message: 'document.images.image0' is null or not an object Line: 13 Char: 1 Code: 0 Here is the code, what am I doing wrong? I can't spot it, theres a couple of threads online from 2005 about this script but none have helped me clear the error. Code: <html> <head> <script language="JavaScript"> image0 =new Image(); image1 =new Image(); image2 =new Image(); image0.src ="http://ec.europa.eu/information_society/activities/egovernment/images/project_logos/sample.jpg" image1.src ="http://ec.europa.eu/information_society/activities/egovernment/images/project_logos/sample.jpg" image2.src ="http://ec.europa.eu/information_society/activities/egovernment/images/project_logos/sample.jpg" document.images['image0'].src=image0.src; document.images['image1'].src=image1.src; document.images['image2'].src=image2.src; function image_click(clicks) { if(clicks==0){document.images['large'].src=image0.src;} if(clicks==1){document.images['large'].src=image1.src;} if(clicks==2){document.images['large'].src=image2.src;} } </script> </head> <body> <a href="javascript:image_click(0)"><img src="http://ec.europa.eu/information_society/activities/egovernment/images/project_logos/sample.jpg" height="93" width="123" alt="" name="image0" border="0"/></a> <a href="javascript:image_click(1)"><img src="http://ec.europa.eu/information_society/activities/egovernment/images/project_logos/sample.jpg" width="123" alt="" name="image1" border="0"/></a> <a href="javascript:image_click(2)"><img src="http://ec.europa.eu/information_society/activities/egovernment/images/project_logos/sample.jpg" height="93" width="123" alt="" name="image2" border="0"/></a> <img src="http://ec.europa.eu/information_society/activities/egovernment/images/project_logos/sample.jpg" align="middle" border="0" width="418" height="284" name="large"> </body> </html> İ want to use this code but when the page opens, I get a null reference error. When I open the page a second time, this error doesn't occur. I understand when the site caches, this error doesn't occur. The error comes from tb_show function. My code: <script type="text/javascript"> function writeCookie(CookieAdi) { var dtGun = 1 var strValue = "1" if (dtGun == null || dtGun == "") dtGun = 365; var d = new Date(); d.setTime(d.getTime() + (dtGun * 24 * 60 * 60 * 1000)); var zt = "; expires=" + d.toGMTString(); document.cookie = CookieAdi + "=" + strValue + zt + "; path=/"; } function readCookie(cookieadi) { var c = document.cookie; if (c.indexOf(cookieadi) != -1) { s1 = c.indexOf("=", c.indexOf(cookieadi)) + 1; s2 = c.indexOf(";", s1); if (s2 == -1) s2 = c.length; strValue = c.substring(s1, s2); return strValue; } } writeCookie('OnerFacebook'); if (readCookie('OnerFacebook') != 1) { tb_show('', 'http://www.mobilyala.com/OnerFacebook/?KeepThis=true&TB_iframe=true&height=500&width=300&modal=true', ''); } </script> What should I do for it? |