ameliabob Posted January 22, 2015 Share Posted January 22, 2015 I have been looking at this for some time and cannot figure out what is different. I have the following code <script type="text/javascript"> function AddBook(){ s = "<table>"; s += "<tr><td>Purchase Date</td><td><input type='text' id ='pdate' width='10'/></td></tr>"; s += "<tr><td>Title</td> <td><input type='text' id ='title' width='75' value='MyBook'/></td></tr>"; s += "<tr><td>Author</td> <td><input type='text' id ='author' width='50'/></td></tr>"; s += "</table>"; s += "<p id='buttons'><button onclick='AddBookFinal()'>Add Book to File</buttton></p>"; document.getElementById("response").innerHTML = s; } function AddBookFinal(){ var title = document.getElementById('title').value; var author = document.getElementById('author').value; var purDate = document.getElementById('pdate').value;alert("addbook&author="+author+"&purDate="+purDate+"&title="+title); // SendOffRequest("addbook&author="+author+"&purDate="+purDate+"&title="+title); }</script> The alert is just for debuggin purposes. The alert does not show anything for the title. There are no errors showing in Firebug and the 3 getElementsById don't seem to function. What am I not seeing? Thanks Link to comment Share on other sites More sharing options...
davej Posted January 22, 2015 Share Posted January 22, 2015 Where is s declared? Also you have a buttton and you might want to trim() the values and use encodeURIComponent(). http://www.w3schools.com/jsref/jsref_encodeuricomponent.asp The code you have posted actually works for me. Link to comment Share on other sites More sharing options...
ameliabob Posted January 22, 2015 Author Share Posted January 22, 2015 s is a global defined outside of the function. I don't see how trimming the 'id' s will do anything to help. The firebug does not day that it cannot find the id'd item. Its just that it returns nothing. I have looked inside the table definitions to see if the id should be there instead of the input item but that doesn't seem to work either. Link to comment Share on other sites More sharing options...
Ingolme Posted January 22, 2015 Share Posted January 22, 2015 Are you calling AddBook more than once? IDs have to be unique, there cannot be more than one of each ID. If there is, then the browser will not behave properly. Also, why can't you just write the HTML right onto the page instead of having Javascript do it? Link to comment Share on other sites More sharing options...
davej Posted January 22, 2015 Share Posted January 22, 2015 It looked like you were creating a URL so you don't want spaces or illegal characters. The code you posted worked for me in FF and Chrome. Link to comment Share on other sites More sharing options...
ameliabob Posted January 22, 2015 Author Share Posted January 22, 2015 Basically because I never learned how. BTW your answer was the problem. I had used the same id elsewhere in the code. thanks Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now